Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
fix(tools): include prohibited_domains in evaluate guard
Saurav Panda8f2967a5c04c
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.pyindex 197f90d2e..8e2cd965f 100644--- a/browser_use/tools/service.py+++ b/browser_use/tools/service.py@@ -1778,15 +1778,16 @@ You will be given a query and the markdown of a webpage that has been filtered t# Refuse on restricted profiles. SecurityWatchdog only hooks navigation,# so evaluate() would otherwise let the agent fetch() internal URLs or# read cookies/localStorage from any allowed origin's context, nullifying- # allowed_domains / block_ip_addresses entirely.+ # the configured restrictions entirely.profile = browser_session.browser_profile- if profile.allowed_domains or profile.block_ip_addresses:+ if profile.allowed_domains or profile.prohibited_domains or profile.block_ip_addresses:return ActionResult(error=(- 'evaluate() is disabled when allowed_domains or block_ip_addresses '- 'is set — this profile is configured as restricted, and evaluate() '- 'would let an agent bypass those restrictions via fetch() and direct '- 'origin access. Run on an unrestricted profile if you need JS evaluation.'+ 'evaluate() is disabled when allowed_domains, prohibited_domains, or '+ 'block_ip_addresses is set — this profile is configured as restricted, '+ 'and evaluate() would let an agent bypass those restrictions via fetch() '+ 'and direct origin access. Run on an unrestricted profile if you need '+ 'JS evaluation.'))diff --git a/tests/ci/security/test_evaluate_restricted.py b/tests/ci/security/test_evaluate_restricted.pyindex f50b87a4e..461d0bc38 100644--- a/tests/ci/security/test_evaluate_restricted.py+++ b/tests/ci/security/test_evaluate_restricted.py@@ -24,8 +24,14 @@ from browser_use.tools.service import Toolsclass _StubProfile:- def __init__(self, allowed_domains: Any = None, block_ip_addresses: bool = False) -> None:+ def __init__(+ self,+ allowed_domains: Any = None,+ prohibited_domains: Any = None,+ block_ip_addresses: bool = False,+ ) -> None:self.allowed_domains = allowed_domains+ self.prohibited_domains = prohibited_domainsself.block_ip_addresses = block_ip_addresses@@ -70,6 +76,15 @@ async def test_evaluate_refused_when_block_ip_addresses_set() -> None:assert 'block_ip_addresses' in result.error.lower() or 'restricted' in result.error.lower()+async def test_evaluate_refused_when_prohibited_domains_set() -> None:+ """`prohibited_domains` is the deny-list counterpart of `allowed_domains`;+ SecurityWatchdog enforces both as navigation restrictions. Refuse evaluate()+ when either is set — otherwise an agent can fetch() into the blocked domains."""+ result = await _run_evaluate(_StubProfile(prohibited_domains=['evil.test']))+ assert result.error is not None+ assert 'prohibited_domains' in result.error.lower() or 'restricted' in result.error.lower()++async def test_evaluate_refused_when_both_restrictions_set() -> None:"""Belt and suspenders configuration — refuse."""result = await _run_evaluate(_StubProfile(allowed_domains=['x.test'], block_ip_addresses=True))