AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Merge branch 'master' into security-and-robustness-improvements
Slava Kurilyak (slavakurilyak.eth)fb36c14517c5
diff --cc scripts/browse.pyindex d07f269978,0fda3d7b06..a758b9a824--- a/scripts/browse.py+++ b/scripts/browse.py@@@ -6,40 -5,12 +6,40 @@@ from urllib.parse import urlparse, urljcfg = Config()+# Function to check if the URL is valid+def is_valid_url(url):+ try:+ result = urlparse(url)+ return all([result.scheme, result.netloc])+ except ValueError:+ return False++# Function to sanitize the URL+def sanitize_url(url):+ return urljoin(url, urlparse(url).path)++# Function to make a request with a specified timeout and handle exceptions+def make_request(url, timeout=10):+ try:- response = requests.get(url, timeout=timeout)++ response = requests.get(url, headers=cfg.user_agent_header, timeout=timeout)+ response.raise_for_status()+ return response+ except requests.exceptions.RequestException as e:+ return "Error: " + str(e)+def scrape_text(url):- response = requests.get(url, headers=cfg.user_agent_header)+ # Validate the input URL+ if not is_valid_url(url):+ return "Error: Invalid URL"++ # Sanitize the input URL+ sanitized_url = sanitize_url(url)++ # Make the request with a timeout and handle exceptions+ response = make_request(sanitized_url)- # Check if the response contains an HTTP error- if response.status_code >= 400:- return "Error: HTTP " + str(response.status_code) + " error"+ if isinstance(response, str):+ return responsesoup = BeautifulSoup(response.text, "html.parser")