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
This commit is contained in:
onekum
2023-04-10 12:10:28 -04:00
committed by GitHub
parent fa8461be9d
commit b60c7518b0

View File

@@ -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: