Skip to content

The agent that grows with you

fix(browser): browser_cdp opens a blank tab while the private-page guard is on

Teknium3c9aad4562d5
diff --git a/tests/tools/test_browser_cdp_tool.py b/tests/tools/test_browser_cdp_tool.py
index 86e17bfc152..e896294b842 100644
--- a/tests/tools/test_browser_cdp_tool.py
+++ b/tests/tools/test_browser_cdp_tool.py
@@ -667,6 +667,12 @@ LOCAL_TAB = "http://127.0.0.1:3000/"
("Target.createTarget", {"url": PUBLIC_PAGE}, True),
("Target.createTarget", {"url": "http://127.0.0.1:3000/admin"}, False), # checked like Page.navigate
("Target.createTarget", {"url": PRIVATE_URL}, False),
+ ("Target.createTarget", {"url": "about:blank"}, True), # a blank tab, as Hermes's own helpers open
+ ("Target.createTarget", {"url": ""}, True),
+ ("Target.createTarget", {}, True),
+ ("Target.createTarget", {"url": "file:///etc/passwd"}, False), # every other non-http scheme stays refused
+ ("Target.createTarget", {"url": "about:[email protected]"}, False),
+ ("Target.createTarget", {"url": "data:text/html,<script>fetch('http://127.0.0.1:3000/')</script>"}, False),
("Target.activateTarget", {"targetId": "tab-public"}, True),
("Target.closeTarget", {"targetId": "tab-public"}, True),
("Network.getAllCookies", {}, False), # every other target-less call stays fail-closed
@@ -674,7 +680,7 @@ LOCAL_TAB = "http://127.0.0.1:3000/"
])
def test_tab_management_stays_usable_while_a_tab_is_private(monkeypatch, cdp_server, method, params, allowed):
"""One private tab (a local dev server) must not stop the model opening, switching or closing tabs; a
- new tab's url is held to Page.navigate's rule, and every other browser-level call is still refused."""
+ new tab is blank or its url is held to Page.navigate's rule, and every other browser-level call is refused."""
cdp_server.on("Target.getTargets", lambda params, sid: {"targetInfos": [
{"targetId": "tab-public", "type": "page", "url": PUBLIC_PAGE},
{"targetId": "tab-local", "type": "page", "url": LOCAL_TAB},
diff --git a/tools/browser_cdp_tool.py b/tools/browser_cdp_tool.py
index 24c0bca6060..e8fe898283e 100644
--- a/tools/browser_cdp_tool.py
+++ b/tools/browser_cdp_tool.py
@@ -140,17 +140,26 @@ def _expression_private_target(params: dict[str, Any]) -> Optional[str]:
def _navigate_private_target(params: dict[str, Any]) -> Optional[str]:
- """Blocked URL literal for ``Page.navigate`` / ``Target.createTarget`` params, else ``None``."""
+ """Blocked URL literal for ``Page.navigate`` params, else ``None``."""
from tools.browser_url_policy import url_blocked
target_url = str(params.get("url") or "").strip()
return target_url if target_url and url_blocked(target_url) else None
+def _new_tab_private_target(params: dict[str, Any]) -> Optional[str]:
+ """``Target.createTarget``: a blank tab (``about:blank``, Chrome's default for no url) reaches nothing, so
+ it opens before scripts are installed or a page is chosen; any other url is held to ``Page.navigate``'s
+ rule (``url_blocked`` refuses every other non-http scheme)."""
+ if str(params.get("url") or "").strip().lower() == "about:blank":
+ return None
+ return _navigate_private_target(params)
+
+
# method → (probe(params) -> blocked literal | None, error template)
_METHOD_PARAM_GUARDS = {
"Page.navigate": (_navigate_private_target,
"Blocked: CDP Page.navigate target is a private or internal address ({})."),
- "Target.createTarget": (_navigate_private_target,
+ "Target.createTarget": (_new_tab_private_target,
"Blocked: CDP Target.createTarget url is a private or internal address ({})."),
"Runtime.evaluate": (_expression_private_target,
"Blocked: CDP Runtime.evaluate expression targets a private or internal address ({})."),