Skip to content

The agent that grows with you

fix(tools): redact vault values from browser exec output

KoNit-Ka48debd368c5
diff --git a/tests/tools/test_browser_use_cli.py b/tests/tools/test_browser_use_cli.py
index 89e00bdab23..4005fb8b7e2 100644
--- a/tests/tools/test_browser_use_cli.py
+++ b/tests/tools/test_browser_use_cli.py
@@ -282,6 +282,25 @@ class TestVaultSupervisorAttach:
assert _fake_supervisor_registry == [("t-vault", "ws://127.0.0.1:47000/devtools/browser/t-vault")]
+class TestVaultEgressRedaction:
+ def test_exec_redacts_registered_vault_secret_from_stdout_and_stderr(self, tmp_path, monkeypatch):
+ """A browser_exec page read must not return a vault-filled value to model history."""
+ from agent import redact
+
+ secret = "vault-filled-password-112693"
+ cli = _fake_cli(tmp_path, f'cat > /dev/null\necho "stdout={secret}"\necho "stderr={secret}" >&2\n')
+ monkeypatch.setattr(bu_cli, "_find_cli", lambda: [cli])
+ redact.register_vault_redaction_value(secret)
+ try:
+ result = json.loads(bu_cli.browser_exec("print(1)"))
+ finally:
+ redact.clear_vault_redaction_values()
+
+ serialized = json.dumps(result, ensure_ascii=False)
+ assert secret not in serialized
+ assert serialized.count("«redacted-vault-secret»") == 2
+
+
class TestFindCli:
"""The tests/tools conftest pins _find_cli to None (host isolation);
exercise the real function via the preserved _find_cli_unpatched."""
diff --git a/tools/browser_use_cli.py b/tools/browser_use_cli.py
index a52ac1b0bbe..1429ea4ceee 100644
--- a/tools/browser_use_cli.py
+++ b/tools/browser_use_cli.py
@@ -604,6 +604,7 @@ def _run_cli_killing_process_group(cmd, code, env, timeout):
def browser_exec(code: str, session: str = "", timeout_s: int = _DEFAULT_TIMEOUT_S,
task_id: Optional[str] = None, local: bool = False):
"""Run Python code through the browser-use CLI, and return its output"""
+ from agent.redact import redact_sensitive_text
from tools.registry import tool_error, tool_result
if not code or not code.strip():
return tool_error("No code provided. Pass Python that uses the pre-imported helpers, e.g. new_tab(\"https://example.com\") then print(page_info()).")
@@ -655,12 +656,18 @@ def browser_exec(code: str, session: str = "", timeout_s: int = _DEFAULT_TIMEOUT
except OSError as e:
return tool_error(f"Failed to launch browser-use CLI: {e}")
- result = {"success": proc.returncode == 0, "exit_code": proc.returncode, "output": proc.stdout}
+ # browser_vault_fill registers injected values with this forced model-egress
+ # boundary. Preserve raw stdout only for screenshot-path detection below.
+ result = {
+ "success": proc.returncode == 0,
+ "exit_code": proc.returncode,
+ "output": redact_sensitive_text(proc.stdout, force=True),
+ }
if workspace:
result["workspace"] = workspace
if session:
result["session"] = session
- stderr = (proc.stderr or "").strip()
+ stderr = redact_sensitive_text((proc.stderr or "").strip(), force=True)
if len(stderr) > _STDERR_CAP_CHARS:
stderr = stderr[:_STDERR_CAP_CHARS] + "\n… (stderr truncated)"
if stderr: