Skip to content

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

Match Rust sensitive-data warnings

Magnus Müller7a0d3b585a9a
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 5ab026b35..ce38e1d9d 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -1066,10 +1066,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- This preserves the constructor diagnostics Browser Use callers see before the Rust terminal core is invoked.
- Proof: `test_rust_agent_constructor_debug_summary_matches_browser_use`.
+211. Rust Agent sensitive-data warning parity
+ - Rust-backed construction now emits Browser Use's exact sensitive-data safety warnings when credentials are provided without locked-down domains or when a domain-scoped credential is not covered by `allowed_domains`.
+ - Secret values remain excluded from the warning text while matching Browser Use's public error/warning messages.
+ - Proof: `test_rust_agent_sensitive_data_warnings_match_browser_use`.
+
## Current Verification
- `python3 -m py_compile browser_use/agent/service.py browser_use/rust/service.py browser_use/rust/__init__.py browser_use/__init__.py tests/ci/test_rust_agent.py examples/rust_agent/basic.py examples/rust_agent/real_v8_smoke.py`
-- `uv run pytest -q tests/ci/test_rust_agent.py` (179 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (180 tests)
- `cargo build -q -p browser-use-cli` on terminal branch `magnus/browser-use-rust-main-integration`
- `cargo test -q -p browser-use-cli run_codex_session_command_accepts_task_id_and_model -- --nocapture`
- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent selected_remote_cdp_mode_allows_remote_cdp_connect -- --nocapture`
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.py
index 0d2662900..41c62c6fb 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -582,8 +582,9 @@ def _warn_sensitive_data_domain_constraints(
return
if not allowed_domains:
logger.error(
- 'Agent(sensitive_data=••••••••) was provided but Browser(allowed_domains=[...]) is not locked down! '
- 'Sensitive data may be exposed if the agent visits a malicious website.'
+ '⚠️ Agent(sensitive_data=••••••••) was provided but Browser(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'
+ ' \n'
)
return
for domain_pattern, value in sensitive_data.items():
@@ -591,9 +592,8 @@ def _warn_sensitive_data_domain_constraints(
continue
if not any(_sensitive_domain_is_allowed(domain_pattern, allowed_domain) for allowed_domain in allowed_domains):
logger.warning(
- f'Domain pattern "{domain_pattern}" in sensitive_data is not covered by any pattern in '
- f'allowed_domains={allowed_domains}. This may be a security risk as credentials could be used on '
- 'unintended domains.'
+ f'⚠️ Domain pattern "{domain_pattern}" in sensitive_data is not covered by any pattern in allowed_domains={allowed_domains}\n'
+ f' This may be a security risk as credentials could be used on unintended domains.'
)
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 34e8e9adb..454963dae 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -2531,6 +2531,57 @@ def test_rust_agent_warns_about_sensitive_data_domain_constraints(monkeypatch):
assert 'uncovered-secret' not in messages
+def test_rust_agent_sensitive_data_warnings_match_browser_use(monkeypatch):
+ from browser_use.agent.service import _PythonAgent as BrowserUseAgent
+ from browser_use.browser import BrowserProfile
+ from browser_use.rust import Agent as RustAgent
+
+ class LLM:
+ model = 'gpt-test'
+ provider = 'test'
+
+ async def ainvoke(self, messages, output_format=None, **kwargs):
+ return type('Result', (), {'usage': None})()
+
+ class RecordingLogger:
+ def __init__(self):
+ self.messages = []
+
+ def info(self, message, *args, **kwargs):
+ pass
+
+ def debug(self, message, *args, **kwargs):
+ pass
+
+ def error(self, message, *args, **kwargs):
+ self.messages.append(('error', message))
+
+ def warning(self, message, *args, **kwargs):
+ self.messages.append(('warning', message))
+
+ for kwargs in (
+ {
+ 'sensitive_data': {'password': 'unlocked-secret'},
+ },
+ {
+ 'browser_profile': BrowserProfile(allowed_domains=['*.example.com']),
+ 'sensitive_data': {'https://evil.test': {'password': 'uncovered-secret'}},
+ },
+ ):
+ browser_use_logger = RecordingLogger()
+ rust_logger = RecordingLogger()
+ monkeypatch.setattr(BrowserUseAgent, 'logger', property(lambda self, logger=browser_use_logger: logger))
+ monkeypatch.setattr(RustAgent, 'logger', property(lambda self, logger=rust_logger: logger))
+
+ BrowserUseAgent(task='Use credentials safely.', llm=LLM(), directly_open_url=False, **kwargs)
+ RustAgent(task='Use credentials safely.', llm=LLM(), directly_open_url=False, **kwargs)
+
+ assert rust_logger.messages == browser_use_logger.messages
+ message_text = '\n'.join(message for _level, message in rust_logger.messages)
+ assert 'unlocked-secret' not in message_text
+ assert 'uncovered-secret' not in message_text
+
+
def test_rust_agent_mirrors_direct_url_startup():
from browser_use.rust import Agent