Commit Graph

4725 Commits

Author SHA1 Message Date
Saurav Panda 0d59615688 security: wrap _safe_import to close __import__.__globals__ bypass
Previously __import__ was a plain closure whose __globals__ contained
this module's real __builtins__, so sandboxed code could escape via
__import__.__globals__['__builtins__']['__import__']('os').

Wrap _safe_import in _SafeBuiltin (same hardening as other builtins) so
its __globals__ attribute is not reachable from user code. Also resolve
_real_import at wrap-time rather than closing over __builtins__ to keep
the closure minimal.
2026-04-14 17:55:43 -07:00
Saurav Panda b53dc30564 security: harden PythonSession sandbox against __globals__ and module leak bypasses
Replace closure wrapper with a callable class (_SafeBuiltin) built in an
isolated exec namespace. Closures leak this module's globals via
wrapper.__globals__ (print.__globals__['io'], print.__globals__['Path']).
The callable class has no __globals__ attribute at instance level, and
the class methods' __globals__ is the isolated namespace instead of this
module.

Also block pathlib and asyncio imports — both modules import os directly,
so Path.cwd.__globals__['os'] and asyncio.subprocess were escape routes.
2026-04-14 17:52:15 -07:00
Saurav Panda 6118f5218d security: sandbox PythonSession namespace, block dangerous modules and builtins
Remove os from the default namespace and restrict __builtins__ to a
curated safe set (no open/exec/eval/compile). Add an import guard that
blocks os, subprocess, shutil, sys, builtins, and other system-access
modules. Preserve __build_class__ so class definitions still work.

Wrap builtin functions to prevent __self__ leaking the builtins module.
Remove Path and asyncio from pre-loaded namespace to close
Path.cwd.__globals__ and asyncio.sys.modules escape routes.
2026-04-14 16:00:05 -07:00
Saurav Panda edc9616dc4 Merge branch 'main' into security/remove-os-from-python-session-namespace 2026-04-14 15:48:09 -07:00
Saurav Panda ce8b13ed88 Merge branch 'main' into security/remove-os-from-python-session-namespace 2026-04-14 11:50:34 -07:00
Saurav Panda 35eef03ecd security: sandbox PythonSession namespace, block dangerous modules and builtins 2026-04-14 11:49:48 -07:00
Shawn Pana d0fbf4c580 improve connect failure UX: fix chrome://inspect link and add fallback guidance
When `browser-use connect` fails to discover a running Chrome, the error
now points to the correct `chrome://inspect/#remote-debugging` URL. The
SKILL.md also guides agents to prompt users with two options: enable
remote debugging or use managed Chromium with a Chrome profile.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 11:23:50 -07:00
laithrw 76604913ad Merge branch 'main' into fix/browser-session-close 2026-04-12 17:45:44 -04:00
Laith Weinberger c1eb87a35f close alias for BrowserSession stop
thousands of users have attempted to use close, so why not add it
2026-04-12 17:43:04 -04:00
Laith Weinberger 03e2bc4da8 prefer Playwright chromium over sys Chrome by default 2026-04-12 11:41:50 -04:00
Laith Weinberger df4e2f9f15 fix: handle BrokenPipeError gracefully when MCP client disconnects 2026-04-12 11:34:39 -04:00
Laith Weinberger 9ad4c63cdb fix pagination classifier to prioritize semantic labels over shared glyph symbols 2026-04-11 18:30:46 -04:00
Laith Weinberger 65f87b7fca fix sensitive_data redaction order to prevent substring leaks 2026-04-11 18:16:24 -04:00
Laith Weinberger 99a8674214 fix asyncio.get_event_loop for python 3.14 cli compatibilit 2026-04-11 18:10:12 -04:00
laithrw 60e7767228 Merge branch 'main' into issue-4631-review 2026-04-11 18:07:12 -04:00
Laith Weinberger 534eaafe7a clear dom cache after scroll to prevent stale extract data 2026-04-11 18:03:06 -04:00
Alezander9 76569995fd Improve OSS-to-cloud conversion: UTM tracking, better error messages, and cloud nudges
- Add UTM params to all cloud-bound links across README, CLI, and error messages
- Rewrite README Open Source vs Cloud section: position cloud browsers as
  recommended pairing for OSS users, remove separate Use Both section
- Rewrite error messages for use_cloud=True and ChatBrowserUse() to clearly
  state what is wrong and what to do next
- Add missing URLs: invalid API key now links to key page, insufficient
  credits now links to billing page
- Add cloud browser nudge on captcha detection (logger.warning)
- Add cloud browser nudge on local browser launch failure
2026-04-08 22:05:50 -07:00
Saurav Panda 1a94f96ce9 fix: update imports for browser-use-sdk 3.4.2 and handle UUID id fields 2026-04-08 17:51:22 -07:00
laithrw 83317179cb Merge branch 'main' into fix/mcp-stdin-guard 2026-04-08 17:25:16 -04:00
Laith Weinberger 674547a414 fix: guard against missing stdin in MCP stdio server startup 2026-04-08 17:21:11 -04:00
Laith Weinberger 3242d9dbc2 fix: use object.__setattr__ for LLM ainvoke patching to avoid pydantic crash 2026-04-08 17:20:46 -04:00
laithrw 6129ceb0b0 Merge branch 'main' into fix/agent-history-safe-access 2026-04-07 14:18:38 -04:00
sauravpanda ca2185ba61 fix: create token temp file with 0o600 at open() time; raise on failure
- Use os.open() with mode 0o600 instead of write-then-chmod to eliminate
  the permission race window where the temp file is briefly world-readable.
- Raise instead of warn when token file write fails: a daemon that cannot
  persist its auth token is permanently unauthorized for all clients, so
  failing fast is correct (identified by cubic).
2026-04-02 17:58:12 -07:00
sauravpanda a05a053da6 fix: add per-session auth token to daemon socket to prevent unauthorized code execution
Generate a secrets.token_hex(32) on daemon startup, write it atomically
to ~/.browser-use/{session}.token (chmod 0o600), and validate it on every
incoming request via hmac.compare_digest. The client reads the token file
and includes it in each send_command() call.

This closes the arbitrary-code-execution vector where any local process
could connect to the deterministic Windows TCP port (or a world-readable
Unix socket) and dispatch the 'python' action to run eval()/exec() as the
daemon owner.
2026-04-02 17:41:15 -07:00
Saurav Panda 14ada65183 Merge branch 'main' into worktree-fix+aiohttp-security-upgrade 2026-04-02 16:31:45 -07:00
sauravpanda 22f0e501e9 fix: upgrade aiohttp to 3.13.4 to patch memory exhaustion vulnerability
Bumps aiohttp from 3.13.3 to 3.13.4 in requirements-cli.txt.
Fixes uncapped memory usage from insufficient trailer header restrictions
(aio-libs/aiohttp@0c2e9da).
2026-04-02 16:26:39 -07:00
sauravpanda 56d8aa8483 fix: address review violations — drop env var fallback, fix cross-fs move
- cloud.py: remove BROWSER_USE_API_KEY env var fallback (violates CLI
  policy of config.json as single source of truth); instead detect the
  env var in the error path and print a targeted migration hint
- setup.py: replace Path.rename() with shutil.move() so the temp file
  can be moved across filesystems (e.g. /tmp -> /usr/local/bin)
2026-04-02 16:21:24 -07:00
sauravpanda ea99055e53 fix: write config.json atomically via tmp+rename to prevent silent data loss
A SIGKILL mid-write truncates config.json; read_config() catches
json.JSONDecodeError and returns {}, silently wiping the API key and
all other settings. Mirror the pattern already used by _write_state():
write to a sibling temp file, fsync, chmod 600, then os.replace() into
place — which is atomic on POSIX and effectively atomic on Windows.
2026-04-02 13:08:37 -07:00
sauravpanda 7a887e156e fix: verify cloudflared binary SHA256 checksum before installing on Linux
Downloads to a temp file, fetches the .sha256sum file Cloudflare publishes
alongside each release, and verifies before moving to the install destination.
Protects against MITM/CDN tampering. Temp file is cleaned up on failure.
2026-04-02 13:08:37 -07:00
sauravpanda 96bb65dcb5 fix: warn on deprecated BROWSER_USE_API_KEY env var instead of silently ignoring it
The CLI previously accepted the env var as a fallback; this PR dropped it
without a migration path, breaking CI/CD pipelines that set it as a secret.
Restore backwards-compat by checking the env var after config.json and
printing a deprecation warning with the migration command.
2026-04-02 13:08:37 -07:00
shawn pana a7b476ee46 Merge branch 'main' into multi-session 2026-04-02 13:02:51 -07:00
ShawnPana 0530545c1a fix: API key single source of truth (config.json only), daemon-safe profile creation
- Remove BROWSER_USE_API_KEY env var as a read source from CLI code; config.json is the only source of truth
- Split _create_cloud_profile into daemon-safe _inner (raises) and CLI wrapper (sys.exit)
- Daemon auto-heal no longer kills process on profile creation API errors
2026-04-02 11:51:38 -07:00
ShawnPana 47ba16b8ab ux: show Connecting.../Closing... status during slow operations 2026-04-02 11:29:03 -07:00
ShawnPana 1deb430f8f perf: skip profile validation HTTP call on cloud connect
_get_or_create_cloud_profile reads config instantly instead of
validating via GET /profiles/{id} on every connect. If the profile
is invalid, _provision_cloud_browser auto-heals by creating a new
one and retrying. Saves ~500ms-1s on every cloud connect.
2026-04-02 11:21:12 -07:00
ShawnPana 63904858f4 fix: CDP URL only in sessions --json, not in table output 2026-04-01 22:40:48 -07:00
ShawnPana 8c6d042a79 fix: truncate CDP URL in sessions table, full URL in --json 2026-04-01 22:39:30 -07:00
ShawnPana b1522b5e23 fix: sessions shows CDP URL for cloud sessions too
Ping response now returns live CDP URL from the browser session
(not just the constructor arg). Cloud sessions show their
provisioned CDP URL.
2026-04-01 22:37:23 -07:00
ShawnPana c09ea5a0b2 feat: sessions command shows CDP URL for each session 2026-04-01 22:35:11 -07:00
ShawnPana d6c9b8a24b fix: reject invalid boolean config values instead of silently coercing to False 2026-04-01 22:29:36 -07:00
ShawnPana f27c567aad fix: enable_recording defaults False in library, configurable in CLI
Library keeps recording off by default. CLI reads cloud_connect_recording
from config (defaults True). Users can disable with:
  browser-use config set cloud_connect_recording false
2026-04-01 22:22:33 -07:00
ShawnPana a2bcc1a3f9 fix: wrap Page.enable in try/except (not supported on root CDP client)
Page.enable fails on browser-level CDP targets. Wrap in try/except
like the library's PopupsWatchdog does. Dialog handler still
registers regardless — events may fire on some CDP implementations.
2026-04-01 22:13:55 -07:00
MagMueller 3aa68384ad style: use TimeoutError instead of asyncio.TimeoutError (py3.11+) 2026-04-01 21:54:58 -07:00
ShawnPana 778984af8e fix: remove unnecessary string quotes on BrowserSession type hint 2026-04-01 21:49:10 -07:00
ShawnPana 92181538d3 fix: type-narrow actions instead of assert (fixes pyright + test compat) 2026-04-01 21:43:56 -07:00
MagMueller dcc7e691c4 fix: add 2s timeout to pending network request check in DOM watchdog
On slow CI machines, _get_pending_network_requests() can hang for 15s+
when Chrome is busy loading/rendering after a navigation. This silently
eats into the 30s BrowserStateRequestEvent budget, leaving insufficient
time for the actual DOM capture — causing 5 consecutive timeouts and
agent termination.

Observed on eBay search results in eval runs: DOMWatchdog started but
produced zero log output for 15 seconds before the timeout killed it.
The pending network check was the first await after the URL log.
2026-04-01 21:40:06 -07:00
ShawnPana 080eeae62a fix: CI type errors and test compatibility
- type: ignore on each param line in sessions.py (pyright per-line)
- Remove ActionHandler assert in browser.py (breaks pre-existing tests)
- Ruff format
2026-04-01 21:39:51 -07:00
shawn pana f9f56b8392 Merge branch 'main' into multi-session 2026-04-01 21:31:42 -07:00
ShawnPana a3b6217e8f fix: SessionInfo.browser_session typed as BrowserSession
Fixes type errors in test_cli_upload and test_cli_coordinate_click
which construct SessionInfo with BrowserSession instances.
2026-04-01 21:31:18 -07:00
ShawnPana 51244762cc fix: ActionHandler accepts BrowserSession (not just CLIBrowserSession)
Fixes type errors in test_cli_upload and test_cli_coordinate_click
which pass BrowserSession. CLIBrowserSession inherits from it so
the runtime behavior is unchanged.
2026-04-01 21:26:08 -07:00
ShawnPana 0bf1f02d97 fix: CI failures — ruff formatting, type errors, test_setup_command
- Ruff format all skill_cli and test files
- Fix type: get_config_value returns str|int|None, callers cast properly
- Fix type: BrowserWrapper.actions is non-optional (always provided)
- Fix type: config comparison uses 'is' not '=='
- Rewrite test_setup_command for new setup.handle(yes=True) API
- Add None guard in test_cli_lifecycle for state file
2026-04-01 19:58:33 -07:00