The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(browser): stop refusing credential-named query params on cloud browser/extract backends
Teknium4140901d15a2
diff --git a/tests/tools/test_browser_secret_exfil.py b/tests/tools/test_browser_secret_exfil.pyindex 1aad081d1c0..af940bec37f 100644--- a/tests/tools/test_browser_secret_exfil.py+++ b/tests/tools/test_browser_secret_exfil.py@@ -28,20 +28,24 @@ class TestBrowserSecretExfil:parsed = json.loads(result)assert parsed["success"] is False- def test_cloud_blocks_opaque_sensitive_query_param(self):- """Cloud browser providers must not receive opaque token query params."""+ def test_cloud_browser_allows_credential_named_query_param(self):+ """Magic links / OAuth callbacks / signed assets carry ``?token=``-style params and must+ reach a cloud browser too: the browser is where the agent signs in, and it already sees the+ session's cookies and typed passwords. Only Hermes-secret-shaped values stay blocked."""from tools.browser_tool import browser_navigate+ url = "https://example.com/callback?token=opaque-oauth-code&signature=abc123"+ mock_result = {"success": True, "data": {"title": "ok", "url": url}}with patch("tools.browser_tool_cloud._is_local_backend", return_value=False), \patch("tools.browser_tool._navigation_session_key", return_value="default"), \- patch("tools.browser_tool_session._run_browser_command") as mock_run:- result = browser_navigate("https://example.com/callback?token=opaque-oauth-code")+ patch("tools.browser_tool_session._get_session_info", return_value={"_first_nav": False}), \+ patch("tools.browser_tool_session._run_browser_command", return_value=mock_result) as mock_run:+ allowed = json.loads(browser_navigate(url))+ blocked = json.loads(browser_navigate("https://example.com/callback?token=" + "sk-or-v1-" + "b" * 30))- parsed = json.loads(result)- assert parsed["success"] is False- assert "credential-like query parameter" in parsed["error"]- assert "token" in parsed["error"]- mock_run.assert_not_called()+ assert allowed["success"] is True+ assert blocked["success"] is False and "Blocked" in blocked["error"]+ assert all(call.args[1] != "open" or "sk-or-v1-" not in call.args[2][0] for call in mock_run.call_args_list)def test_local_browser_allows_opaque_sensitive_query_param(self):"""Local browser/CDP sessions may navigate magic-link style URLs."""@@ -104,17 +108,15 @@ class TestWebExtractSecretExfil:assert "Blocked" in parsed["error"]@pytest.mark.asyncio- async def test_blocks_opaque_sensitive_query_param(self):+ async def test_allows_credential_named_query_param(self):+ """``?access_token=`` is how magic links and signed URLs look; the extract backend may fetch them.+ Only Hermes-secret-shaped VALUES are blocked (see test_blocks_api_key_in_url)."""from tools.web_tools import web_extract_tool- result = await web_extract_tool(- urls=["https://example.com/callback?access_token=opaque-oauth-value"],- )-+ result = await web_extract_tool(urls=["https://example.com/callback?access_token=opaque-oauth-value"])parsed = json.loads(result)- assert parsed["success"] is False- assert "credential-like query parameter" in parsed["error"]- assert "access_token" in parsed["error"]+ assert "credential-like query parameter" not in parsed.get("error", "")+ assert "Blocked" not in parsed.get("error", "")@pytest.mark.asyncioasync def test_allows_ambiguous_english_word_query_param(self):diff --git a/tools/browser_tool.py b/tools/browser_tool.pyindex 63e8bec2c0f..7b33d54fd47 100644--- a/tools/browser_tool.py+++ b/tools/browser_tool.py@@ -55,13 +55,11 @@ try:is_safe_url as _is_safe_url,is_always_blocked_url as _is_always_blocked_url,normalize_url_for_request as _normalize_url_for_request,- sensitive_query_param_name as _sensitive_query_param_name,)except Exception:_is_safe_url = lambda url: False # noqa: E731 — fail-closed: block all if safety module unavailable_is_always_blocked_url = lambda url: True # noqa: E731 — fail-closed on the floor too_normalize_url_for_request = lambda url: url # noqa: E731 — best-effort fallback- _sensitive_query_param_name = lambda url: None # noqa: E731 — best-effort fallback# Browser-provider ABC + registry; per-vendor providers live under# ``plugins/browser/<vendor>/``. The dispatcher consults the registry. See #25214.from agent.browser_provider import BrowserProvider@@ -598,18 +596,15 @@ def _secret_url_error(url: str) -> Optional[dict]:def _url_policy_error(url: str, *, auto_local: bool = False) -> Optional[dict]:"""Backend-aware URL checks on an already-normalized URL; None if allowed. Ordered floors:- (1) credential-like query params refused for cloud backends (third-party readers);- (2) cloud metadata / IMDS refused UNCONDITIONALLY (a local Chromium on a cloud VM still- reaches the host IMDS); (3) private addresses refused unless local, sidecar-routed, or- ``browser.allow_private_urls``; (4) website policy allow/deny lists."""+ (1) cloud metadata / IMDS refused UNCONDITIONALLY (a local Chromium on a cloud VM still+ reaches the host IMDS); (2) private addresses refused unless local, sidecar-routed, or+ ``browser.allow_private_urls``; (3) website policy allow/deny lists.++ Credential-NAMED query params (``?token=``, ``?signature=``) are deliberately NOT a floor:+ magic links, OAuth callbacks and signed CDN assets are how the agent signs in and browses, and+ a cloud browser already sees every cookie and typed password of the session — refusing the+ URL protects nothing. Hermes' own secrets leaking into a URL are caught by ``_secret_url_error``."""local = _cloud._is_local_backend()- sensitive_query_key = _sensitive_query_param_name(url)- if sensitive_query_key and not local and not auto_local:- return _err(- "Blocked: URL contains a credential-like query parameter "- f"({sensitive_query_key}). Cloud browser backends are third-party "- "readers; use a local browser/CDP session or remove the sensitive "- "query parameter before navigating.")# Always-blocked floor: cloud metadata / IMDS endpoints are denied regardless of backend, hybrid# routing, or allow_private_urls. There's no legitimate agent use case for navigating to 169.254.169.254# / metadata.google.internal / ECS task metadata via a browser, and routing those to a local Chromiumdiff --git a/tools/web_tools_extract.py b/tools/web_tools_extract.pyindex ba0c1c485cb..9f4d5bfad3f 100644--- a/tools/web_tools_extract.py+++ b/tools/web_tools_extract.py@@ -12,7 +12,7 @@ import loggingfrom typing import Any, Dict, List, Optionalfrom tools.tool_backend_helpers import selection_error, selection_exists-from tools.url_safety import normalize_url_for_request, sensitive_query_param_name+from tools.url_safety import normalize_url_for_requestfrom tools.web_tools_rescue import _rescue_eligible, _rescue_extractlogger = logging.getLogger("tools.web_tools")@@ -103,13 +103,6 @@ def _validate_extract_urls(urls: List[Any]):"Blocked: URL contains what appears to be an API key or token. ""Secrets must not be sent in URLs.")- if sensitive_query_key := sensitive_query_param_name(normalized_url):- return _refuse_all(- "Blocked: URL contains a credential-like query parameter "- f"({sensitive_query_key}). Web extract backends are third-party "- "readers; remove the sensitive query parameter or use a local "- "browser session when this access is explicitly required."- )normalized_urls.append(normalized_url)normalized_indices.append(index)return normalized_urls, normalized_indices, invalid_urls, None