Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

fix security issue with url parsing

Nick Sweetingebdeb613f7bd
diff --git a/browser_use/browser/context.py b/browser_use/browser/context.py
index 75461a010..9e06c6c8b 100644
--- a/browser_use/browser/context.py
+++ b/browser_use/browser/context.py
@@ -743,16 +743,15 @@ class BrowserContext:
try:
from urllib.parse import urlparse
- parsed_url = urlparse(url)
- domain = parsed_url.netloc.lower()
-
# Special case: Allow 'about:blank' explicitly
if url == 'about:blank':
return True
- # Remove port number if present
- if ':' in domain:
- domain = domain.split(':')[0]
+ parsed_url = urlparse(url)
+
+ # Extract only the hostname component (without auth credentials or port)
+ # Hostname returns only the domain portion, ignoring username:password and port
+ domain = parsed_url.hostname.lower() if parsed_url.hostname else ''
# Check if domain matches any allowed domain pattern
return any(