Skip to content

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

show massive security warning if sensitive_data is set without allowed_domains restriction

Nick Sweetingdb2271305ac8
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 7cc37bd2d..eae809332 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -5,6 +5,7 @@ import json
import logging
import os
import re
+import sys
import time
from collections.abc import Awaitable, Callable
from pathlib import Path
@@ -281,6 +282,26 @@ class Agent(Generic[Context]):
else:
self.memory = None
+ # Huge security warning if sensitive_data is provided but allowed_domains is not set
+ if self.sensitive_data and not self.browser.config.new_context_config.allowed_domains:
+ logger.error(
+ '⚠️⚠️⚠️ Agent(sensitive_data=••••••••) was provided but BrowserContextConfig(allowed_domains=[...]) is not locked down! ⚠️⚠️⚠️\n'
+ ' ☠️ If the agent visits a malicious website and encounters a prompt-injection attack, your sensitive_data may be exposed!\n\n'
+ ' https://docs.browser-use.com/customize/browser-settings#restrict-urls\n'
+ 'Waiting 30 seconds before continuing... Press [Ctrl+C] to abort.'
+ )
+ if not sys.stdin.isatty():
+ try:
+ time.sleep(30)
+ except KeyboardInterrupt:
+ print(
+ '\n\n 🛑 Exiting now... set BrowserContextConfig(allowed_domains=["example.com", "example.org"]) to only domains you trust to see your sensitive_data.'
+ )
+ sys.exit(0)
+ else:
+ pass # no point waiting if we're not in an interactive shell
+ logger.warning('‼️ Continuing with insecure settings for now... but this will become a hard error in the future!')
+
# Browser setup
self.injected_browser = browser is not None
self.injected_browser_context = browser_context is not None