Skip to content

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

Warn on unsafe Rust agent sensitive data domains

Magnus Müllere185e554db3e
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 138fe2d06..452ee6caa 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -800,10 +800,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- This keeps benchmark cloud smokes on the public Browser Use timeout interface instead of requiring task-specific runner edits when real_v8 tasks exceed the 120-second default.
- Proof: `test_real_v8_smoke_passes_step_timeout_to_agent`.
+158. Rust Agent sensitive-data domain warning parity
+ - The Rust-backed Agent now mirrors Browser Use's sensitive-data safety warnings when credentials are supplied without `allowed_domains`, or when domain-scoped sensitive data is not covered by the configured allowed-domain patterns.
+ - Warnings include placeholder/domain metadata but do not log raw secret values.
+ - Proof: `test_rust_agent_warns_about_sensitive_data_domain_constraints`.
+
## 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` (129 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (130 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 1db0ea878..09dcee6f5 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -529,6 +529,41 @@ def _sensitive_data_context(sensitive_data: dict[str, str | dict[str, str]] | No
}
+def _sensitive_domain_is_allowed(domain_pattern: str, allowed_domain: str) -> bool:
+ if domain_pattern == allowed_domain or allowed_domain == '*':
+ return True
+ pattern_domain = domain_pattern.split('://')[-1] if '://' in domain_pattern else domain_pattern
+ allowed_domain_part = allowed_domain.split('://')[-1] if '://' in allowed_domain else allowed_domain
+ return pattern_domain == allowed_domain_part or (
+ allowed_domain_part.startswith('*.')
+ and (pattern_domain == allowed_domain_part[2:] or pattern_domain.endswith('.' + allowed_domain_part[2:]))
+ )
+
+
+def _warn_sensitive_data_domain_constraints(
+ logger: logging.Logger,
+ sensitive_data: dict[str, str | dict[str, str]] | None,
+ allowed_domains: list[str],
+) -> None:
+ if not sensitive_data:
+ 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.'
+ )
+ return
+ for domain_pattern, value in sensitive_data.items():
+ if not isinstance(value, dict):
+ 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.'
+ )
+
+
def _navigation_url_from_action(action: Any) -> str | None:
if not isinstance(action, dict):
return None
@@ -2490,6 +2525,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
)
self.browser_storage_state = _extract_browser_storage_state(self.browser_session, self.browser_profile)
self.sensitive_data_context = _sensitive_data_context(sensitive_data)
+ _warn_sensitive_data_domain_constraints(self.logger, sensitive_data, self.allowed_domains)
self.display_files_in_done_text = display_files_in_done_text
self.has_downloads_path = getattr(self.browser_profile, 'downloads_path', None) is not None
self._last_known_downloads: list[str] = []
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index ed7fe3c46..d4a8943fa 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -2398,6 +2398,54 @@ def test_rust_agent_adds_sensitive_data_placeholders_without_values():
assert 'super-secret-password' not in agent.task
+def test_rust_agent_warns_about_sensitive_data_domain_constraints(monkeypatch):
+ from browser_use.rust import Agent
+
+ class RecordingLogger:
+ def __init__(self):
+ self.messages = []
+
+ def error(self, message, *args, **kwargs):
+ self.messages.append(('error', message))
+
+ def warning(self, message, *args, **kwargs):
+ self.messages.append(('warning', message))
+
+ logger = RecordingLogger()
+ monkeypatch.setattr(Agent, 'logger', property(lambda self: logger))
+
+ Agent(
+ task='Use credentials safely.',
+ sensitive_data={'password': 'super-secret-password'},
+ directly_open_url=False,
+ )
+
+ messages = '\n'.join(message for _level, message in logger.messages)
+ assert 'not locked down' in messages
+ assert 'super-secret-password' not in messages
+
+ logger.messages.clear()
+
+ class BrowserProfile:
+ allowed_domains = ['*.example.com']
+
+ Agent(
+ task='Use domain-scoped credentials safely.',
+ browser_profile=BrowserProfile(),
+ sensitive_data={
+ 'https://secure.example.com': {'password': 'covered-secret'},
+ 'https://evil.test': {'token': 'uncovered-secret'},
+ },
+ directly_open_url=False,
+ )
+
+ messages = '\n'.join(message for _level, message in logger.messages)
+ assert 'Domain pattern "https://evil.test" in sensitive_data is not covered' in messages
+ assert 'https://secure.example.com' not in messages
+ assert 'covered-secret' not in messages
+ assert 'uncovered-secret' not in messages
+
+
def test_rust_agent_mirrors_direct_url_startup():
from browser_use.rust import Agent