Skip to content

Commit

Permalink
fix: Update URL validation to allow non-local domains
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Pwuts committed Nov 23, 2023
1 parent 1ba917a commit 84afbf6
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions autogpts/autogpt/autogpt/url_utils/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 84afbf6

Please sign in to comment.