-
Notifications
You must be signed in to change notification settings - Fork 11
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
Update app.py #337
Conversation
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
user-provided value
Show autofix suggestion
Hide autofix suggestion
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.
-
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.
- Validate the
-
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.
-
Specific Changes:
- Add a list of trusted domains.
- Add a validation function.
- Modify the
download_model
function to use this validation function.
-
Copy modified line R7 -
Copy modified line R10376 -
Copy modified lines R10378-R10383 -
Copy modified lines R10408-R10410
@@ -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: |
What type of PR is this?