fix: Update URL validation to allow non-local domains

- Modify the check_local_file_access function to only check for local file prefixes and return True if the URL starts with any of them.
- Remove the section of code that parsed the URL and checked if the hostname was in a list of local domains.

This change fixes the URL validation in the validators.py file. Previously, only local domains were allowed. After the change, non-local domains are allowed again.

(Note: this change was made in response to PR #5318 where the validation was modified to allow more local domains, but also accidentally to block any non-local domain.
pull/5659/merge
Reinier van der Leer 2023-11-23 10:45:07 +01:00
parent 1ba917a3e2
commit 84afbf6b45
No known key found for this signature in database
GPG Key ID: CDC1180FDAE06193
1 changed files with 2 additions and 20 deletions

View File

@ -86,23 +86,5 @@ def check_local_file_access(url: str) -> bool:
"file:///",
"file://localhost",
]
if any(url.startswith(prefix) for prefix in local_file_prefixes):
return True
# Parse the URL
parsed = urlparse(url)
# List of local hostnames/IPs without considering ports
local_domains = [
"localhost",
"2130706433", # IP representation of 127.0.0.1
"127.0.0.1",
"0.0.0.0",
"0000" # Not sure what this is for, but keeping it as in original
]
# Check if the domain part of the URL is in local_domains
if parsed.hostname in local_domains:
return False # We don't restrict localhost access on different ports
# Return True for anything else that is deemed "local"
return True
return any(url.startswith(prefix) for prefix in local_file_prefixes)