Skip to content

The agent that grows with you

fix(browser): keep local_browser inside the private-URL policy and the existing local session

Jan-Stefan Janetzky0f56937cd7c3
diff --git a/tests/tools/test_browser_real_profile.py b/tests/tools/test_browser_real_profile.py
index 6c8e22d62db..66f2f3fe18a 100644
--- a/tests/tools/test_browser_real_profile.py
+++ b/tests/tools/test_browser_real_profile.py
@@ -1,7 +1,7 @@
"""Tests for real-profile local browser resolution + routing."""
import os
import ntpath
-from unittest.mock import patch
+from unittest.mock import Mock, patch
import pytest
@@ -99,10 +99,51 @@ class TestLocalBrowserRouting:
self._reset()
with patch.object(bt, "_get_cdp_override_raw", return_value=""), \
patch.object(bt, "_is_camofox_mode", return_value=False), \
+ patch.object(bt, "_get_cloud_provider", return_value=Mock()), \
+ patch.object(bt, "_url_is_private", return_value=False), \
patch.object(bt, "_use_real_profile", return_value=True):
key = bt._navigation_session_key("t1", "https://example.com", local_browser=True)
assert key == "t1::local"
+ def test_local_browser_without_cloud_provider_keeps_bare_session(self):
+ """Pure local backend: the bare session already is the (real-profile)
+ local Chromium; a second ``::local`` session would fight it for the
+ same user-data-dir."""
+ import tools.browser_tool as bt
+ self._reset()
+ with patch.object(bt, "_get_cdp_override_raw", return_value=""), \
+ patch.object(bt, "_is_camofox_mode", return_value=False), \
+ patch.object(bt, "_get_cloud_provider", return_value=None), \
+ patch.object(bt, "_use_real_profile", return_value=True):
+ key = bt._navigation_session_key("t1", "https://example.com", local_browser=True)
+ assert key == "t1"
+
+ def test_local_browser_respects_private_url_opt_out(self):
+ """auto_local_for_private_urls: false is the user's LAN routing
+ decision; a model-supplied flag must not override it."""
+ import tools.browser_tool as bt
+ self._reset()
+ with patch.object(bt, "_get_cdp_override_raw", return_value=""), \
+ patch.object(bt, "_is_camofox_mode", return_value=False), \
+ patch.object(bt, "_get_cloud_provider", return_value=Mock()), \
+ patch.object(bt, "_url_is_private", return_value=True), \
+ patch.object(bt, "_auto_local_for_private_urls", return_value=False), \
+ patch.object(bt, "_use_real_profile", return_value=True):
+ key = bt._navigation_session_key("t1", "http://192.168.1.1/admin", local_browser=True)
+ assert key == "t1"
+
+ def test_local_browser_private_url_follows_auto_local_when_allowed(self):
+ import tools.browser_tool as bt
+ self._reset()
+ with patch.object(bt, "_get_cdp_override_raw", return_value=""), \
+ patch.object(bt, "_is_camofox_mode", return_value=False), \
+ patch.object(bt, "_get_cloud_provider", return_value=Mock()), \
+ patch.object(bt, "_url_is_private", return_value=True), \
+ patch.object(bt, "_auto_local_for_private_urls", return_value=True), \
+ patch.object(bt, "_use_real_profile", return_value=True):
+ key = bt._navigation_session_key("t1", "http://192.168.1.1/admin", local_browser=True)
+ assert key == "t1::local"
+
def test_local_browser_ignored_without_consent(self):
import tools.browser_tool as bt
self._reset()
diff --git a/tools/browser_tool.py b/tools/browser_tool.py
index f1c3a4fabaa..0b6ce0b0204 100644
--- a/tools/browser_tool.py
+++ b/tools/browser_tool.py
@@ -1573,10 +1573,14 @@ def _navigation_session_key(task_id: str, url: str, local_browser: bool = False)
continues to serve public URLs.
``local_browser=True`` (the model-facing arg) forces the ``::local`` sidecar
- regardless of the URL — but ONLY when the user consented to real-profile
+ for the backend choice — but ONLY when the user consented to real-profile
browsing (``browser.use_real_profile``). Without consent the flag is ignored
(the caller surfaces a note); it never silently routes to the real profile.
- A CDP override or Camofox mode still owns the session and is not overridden.
+ It does not override the private-URL policy: a private URL is still routed
+ exactly as ``browser.auto_local_for_private_urls`` says. Without a cloud
+ provider the bare session is already local (and already carries the real
+ profile when consented), so the flag adds nothing there. A CDP override or
+ Camofox mode still owns the session and is not overridden.
"""
if task_id is None:
task_id = "default"
@@ -1584,10 +1588,18 @@ def _navigation_session_key(task_id: str, url: str, local_browser: bool = False)
return task_id
if _is_camofox_mode():
return task_id
- if local_browser and _use_real_profile():
- return f"{task_id}{_LOCAL_SUFFIX}"
if _get_cloud_provider() is None:
+ # Already local. A second ``::local`` session for the same task would
+ # contend with the bare one for the same user-data-dir.
return task_id
+ if local_browser and _use_real_profile():
+ # Every private-URL gate in browser_navigate keys off the sidecar
+ # key, so honouring the flag for a private URL while the user opted
+ # out of auto-local routing would turn a model-supplied argument
+ # into a LAN policy override.
+ if _url_is_private(url) and not _auto_local_for_private_urls():
+ return task_id
+ return f"{task_id}{_LOCAL_SUFFIX}"
if not _auto_local_for_private_urls():
return task_id
if not _url_is_private(url):