Skip to content

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

Bridge Rust agent sensitive data placeholders

Magnus Müller0bd33b521383
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 8f420a9b7..90b81e2ea 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -105,10 +105,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai
- Saved Rust histories can be loaded, and reruns execute through the Rust terminal core while returning Browser Use-style `ActionResult` lists.
- Proof: `test_rust_agent_rerun_history_delegates_to_rust_run` and `test_rust_agent_load_and_rerun_loads_saved_rust_history`.
+20. Sensitive data placeholder bridge
+ - `sensitive_data` is now converted into sanitized placeholder context for the Rust-backed task.
+ - Global and domain-scoped placeholder names are exposed, but raw secret values are not added to the task text.
+ - Proof: `test_rust_agent_adds_sensitive_data_placeholders_without_values`.
+
## Current Verification
- `python3 -m py_compile 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` (29 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (30 tests)
- `cargo build -q -p browser-use-cli`
- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent selected_remote_cdp_mode_allows_remote_cdp_connect -- --nocapture`
- Managed-headless end-to-end:
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.py
index cbd58486f..71b24b72f 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -134,6 +134,24 @@ def _extract_profile_domains(
return values
+def _sensitive_data_context(sensitive_data: dict[str, str | dict[str, str]] | None) -> dict[str, Any]:
+ if not sensitive_data:
+ return {'global_placeholders': [], 'domain_placeholders': {}}
+ global_placeholders: list[str] = []
+ domain_placeholders: dict[str, list[str]] = {}
+ for key, value in sensitive_data.items():
+ if isinstance(value, dict):
+ placeholders = sorted(name for name, secret in value.items() if isinstance(name, str) and name and secret)
+ if placeholders:
+ domain_placeholders[key] = placeholders
+ elif isinstance(value, str) and value:
+ global_placeholders.append(key)
+ return {
+ 'global_placeholders': sorted(global_placeholders),
+ 'domain_placeholders': domain_placeholders,
+ }
+
+
def _navigation_url_from_action(action: Any) -> str | None:
if not isinstance(action, dict):
return None
@@ -194,6 +212,23 @@ def _task_with_domain_constraints(task: str, allowed_domains: list[str], prohibi
return f'{task}\n\n' + '\n'.join(sections)
+def _task_with_sensitive_data_context(task: str, sensitive_context: dict[str, Any]) -> str:
+ global_placeholders = sensitive_context.get('global_placeholders') or []
+ domain_placeholders = sensitive_context.get('domain_placeholders') or {}
+ if not global_placeholders and not domain_placeholders:
+ return task
+ sections = ['Sensitive data placeholders are available. Use <secret>placeholder</secret> when a matching secret is needed.']
+ if global_placeholders:
+ sections.append('Global placeholders:')
+ sections.extend(f'- {placeholder}' for placeholder in global_placeholders)
+ if domain_placeholders:
+ sections.append('Domain-scoped placeholders:')
+ for domain, placeholders in domain_placeholders.items():
+ sections.append(f'- {domain}: {", ".join(placeholders)}')
+ sections.append('Do not reveal placeholder values in the final answer.')
+ return f'{task}\n\n' + '\n'.join(sections)
+
+
def _extract_start_url(task: str) -> str | None:
task_without_emails = re.sub(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', '', task)
patterns = [
@@ -526,6 +561,7 @@ class Agent(Generic[AgentStructuredOutput]):
self.available_file_paths = available_file_paths or []
self.allowed_domains = _extract_profile_domains(self.browser_session, self.browser_profile, 'allowed_domains')
self.prohibited_domains = _extract_profile_domains(self.browser_session, self.browser_profile, 'prohibited_domains')
+ self.sensitive_data_context = _sensitive_data_context(sensitive_data)
self.display_files_in_done_text = display_files_in_done_text
self.file_system_path = file_system_path
self.directly_open_url = directly_open_url
@@ -540,10 +576,13 @@ class Agent(Generic[AgentStructuredOutput]):
self.initial_actions = initial_actions
self.task = _task_with_schema(
_task_with_available_files(
- _task_with_domain_constraints(
- _task_with_initial_actions(task, initial_actions),
- self.allowed_domains,
- self.prohibited_domains,
+ _task_with_sensitive_data_context(
+ _task_with_domain_constraints(
+ _task_with_initial_actions(task, initial_actions),
+ self.allowed_domains,
+ self.prohibited_domains,
+ ),
+ self.sensitive_data_context,
),
self.available_file_paths,
),
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index f0b22548d..ae24759ac 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -207,6 +207,29 @@ def test_rust_agent_adds_browser_profile_domain_constraints():
assert '- ads.example.com' in agent.task
+def test_rust_agent_adds_sensitive_data_placeholders_without_values():
+ from browser_use.rust import Agent
+
+ agent = Agent(
+ task='Log in to the portal.',
+ sensitive_data={
+ 'username': '[email protected]',
+ 'https://example.com': {'password': 'super-secret-password'},
+ },
+ )
+
+ assert agent.sensitive_data_context == {
+ 'global_placeholders': ['username'],
+ 'domain_placeholders': {'https://example.com': ['password']},
+ }
+ assert 'Sensitive data placeholders are available.' in agent.task
+ assert '- username' in agent.task
+ assert '- https://example.com: password' in agent.task
+ assert '<secret>placeholder</secret>' in agent.task
+ assert '[email protected]' not in agent.task
+ assert 'super-secret-password' not in agent.task
+
+
def test_rust_agent_mirrors_direct_url_startup():
from browser_use.rust import Agent