Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update app.py #337

Merged
merged 1 commit into from
Oct 29, 2024
Merged

Update app.py #337

merged 1 commit into from
Oct 29, 2024

Conversation

Dartvauder
Copy link
Owner

What type of PR is this?

  • Refactor
  • Feature
  • [V] Bug Fix
  • Optimization
  • Documentation Update

@Dartvauder Dartvauder self-assigned this Oct 29, 2024
@Dartvauder Dartvauder merged commit bf15be4 into main Oct 29, 2024
2 checks passed
file_name = model_url.split("/")[-1]
file_path = os.path.join(model_path, file_name)
response = requests.get(model_url, allow_redirects=True)
response = requests.get(model_url, allow_redirects=True, stream=True)

Check failure

Code scanning / CodeQL

Full server-side request forgery Critical

The full URL of this request depends on a
user-provided value
.

Copilot Autofix AI 10 days ago

To fix the SSRF vulnerability, we need to validate the model_url input to ensure it only allows URLs from trusted sources. One way to achieve this is by maintaining a whitelist of allowed domains and ensuring the user-provided URL matches one of these domains. This approach will prevent users from directing requests to arbitrary, potentially malicious servers.

  1. General Fix Approach:

    • Validate the model_url against a whitelist of trusted domains.
    • Reject or sanitize any URLs that do not match the trusted domains.
  2. Detailed Fix:

    • Define a list of trusted domains.
    • Implement a validation function to check if the model_url belongs to one of the trusted domains.
    • Use this validation function before making the HTTP request.
  3. Specific Changes:

    • Add a list of trusted domains.
    • Add a validation function.
    • Modify the download_model function to use this validation function.
Suggested changeset 1
LaunchFile/app.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/LaunchFile/app.py b/LaunchFile/app.py
--- a/LaunchFile/app.py
+++ b/LaunchFile/app.py
@@ -6,2 +6,3 @@
 import importlib
+from urllib.parse import urlparse
 os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -10374,3 +10375,10 @@
 }
+TRUSTED_DOMAINS = ["huggingface.co", "example.com"]
 
+def is_valid_url(url, trusted_domains):
+    try:
+        parsed_url = urlparse(url)
+        return any(parsed_url.netloc.endswith(domain) for domain in trusted_domains)
+    except Exception:
+        return False
 
@@ -10399,2 +10407,5 @@
             progress(0.3, desc="Downloading file")
+            if not is_valid_url(model_url, TRUSTED_DOMAINS):
+                gr.Error("Invalid or untrusted model URL")
+                return None
             if "blob/main" in model_url:
EOF
@@ -6,2 +6,3 @@
import importlib
from urllib.parse import urlparse
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@@ -10374,3 +10375,10 @@
}
TRUSTED_DOMAINS = ["huggingface.co", "example.com"]

def is_valid_url(url, trusted_domains):
try:
parsed_url = urlparse(url)
return any(parsed_url.netloc.endswith(domain) for domain in trusted_domains)
except Exception:
return False

@@ -10399,2 +10407,5 @@
progress(0.3, desc="Downloading file")
if not is_valid_url(model_url, TRUSTED_DOMAINS):
gr.Error("Invalid or untrusted model URL")
return None
if "blob/main" in model_url:
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant