mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 22:44:21 +01:00
Merge pull request #690 from onekum/patch-2
Restrict browse from accessing local files
This commit is contained in:
@@ -5,12 +5,21 @@ from llm_utils import create_chat_completion
|
|||||||
|
|
||||||
cfg = Config()
|
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):
|
def scrape_text(url):
|
||||||
"""Scrape text from a webpage"""
|
"""Scrape text from a webpage"""
|
||||||
# Most basic check if the URL is valid:
|
# Most basic check if the URL is valid:
|
||||||
if not url.startswith('http'):
|
if not url.startswith('http'):
|
||||||
return "Error: Invalid URL"
|
return "Error: Invalid URL"
|
||||||
|
|
||||||
|
# Restrict access to local files
|
||||||
|
if check_local_file_access(url):
|
||||||
|
return "Error: Access to local files is restricted"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, headers=cfg.user_agent_header)
|
response = requests.get(url, headers=cfg.user_agent_header)
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
@@ -126,4 +135,4 @@ def summarize_text(text, question):
|
|||||||
max_tokens=300,
|
max_tokens=300,
|
||||||
)
|
)
|
||||||
|
|
||||||
return final_summary
|
return final_summary
|
||||||
|
|||||||
Reference in New Issue
Block a user