From 84afbf6b45ad2a0a3a92241ab8fe53d461d6a1cb Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Thu, 23 Nov 2023 10:45:07 +0100 Subject: [PATCH] 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. --- .../autogpt/autogpt/url_utils/validators.py | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/autogpts/autogpt/autogpt/url_utils/validators.py b/autogpts/autogpt/autogpt/url_utils/validators.py index 40cc4cb0..0bf4e924 100644 --- a/autogpts/autogpt/autogpt/url_utils/validators.py +++ b/autogpts/autogpt/autogpt/url_utils/validators.py @@ -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)