mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 22:14:28 +01:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user