diff --git a/scripts/browse.py b/scripts/browse.py index 4a73d92320..09f376a70a 100644 --- a/scripts/browse.py +++ b/scripts/browse.py @@ -5,6 +5,11 @@ from llm_utils import create_chat_completion cfg = Config() +# Define and check for local file address prefixes +def check_local_file_access(url): + local_prefixes = ['file:///', 'file://localhost', 'http://localhost', 'https://localhost'] + return any(url.startswith(prefix) for prefix in local_prefixes) + def scrape_text(url): """Scrape text from a webpage""" # Most basic check if the URL is valid: @@ -12,7 +17,7 @@ def scrape_text(url): return "Error: Invalid URL" # Restrict access to local files - if url.startswith('file://') or url.startswith('file://localhost'): + if check_local_file_access(url): return "Error: Access to local files is restricted" try: