Merge branch 'master' into security-and-robustness-improvements

This commit is contained in:
Slava Kurilyak (slavakurilyak.eth)
2023-04-11 09:32:51 -06:00
committed by GitHub
16 changed files with 117 additions and 81 deletions

View File

@@ -27,11 +27,20 @@ def make_request(url, timeout=10):
except requests.exceptions.RequestException as e:
return "Error: " + str(e)
# 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"""
# Basic check if the URL is valid
if not url.startswith('http'):
return "Error: Invalid URL"
# Restrict access to local files
if check_local_file_access(url):
return "Error: Access to local files is restricted"
# Validate the input URL
if not is_valid_url(url):
@@ -155,4 +164,4 @@ def summarize_text(text, question):
max_tokens=300,
)
return final_summary
return final_summary