From b60c7518b0640ae224f989a2cd964b37e0ca90bf Mon Sep 17 00:00:00 2001 From: onekum <55006697+onekum@users.noreply.github.com> Date: Mon, 10 Apr 2023 12:10:28 -0400 Subject: [PATCH] Rework local file address blocks add `def check_local_file_access`, which defines and checks for local file address prefixes; use it to restrict access --- scripts/browse.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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: