Skip to content

feat(claude): refuse shell commands that open a browser window on the desktop - #28

Merged
zereight merged 1 commit into
mainfrom
feat/block-external-browser-launch
Nov 14, 2026
Merged

zereight merged 1 commit into
mainfrom
feat/block-external-browser-launch

Conversation

@zereight

@zereight zereight commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changed

A PreToolUse hook now denies a shell command that opens a browser window on the person's desktop, and tells the bot to use its own browser tools, retry once, then stop and report.

  • server/hooks/browser-launch-guard.ts (new): decides from a tokenized command (quotes, ;/&&/pipes, heredocs, bash -c/eval nesting up to 4 levels). Refuses open <url|page|-a browser>, xdg-open/gio open/wslview, start/explorer <url>, browser binaries without --headless, osascript that activates/opens/reopens/makes a window, interpreters that call webbrowser.open, headless=False or open -a "Google Chrome", and headed playwright/agent-browser/puppeteer. Allows --headless, open -g (background), --version/--help, read-only osascript, and a browser name that is only an argument to grep/echo/curl.
  • server/hooks/omb-browser-guard.ts (new): the hook entry. Always exits 0 and fails open on any error or an oversized payload.
  • server/drivers/claude-hook-settings.ts (new): hookCommand, claudeHookSettings and the new browserGuardHookSettings moved out of claude.ts (file-size ratchet); claude.ts re-exports them.
  • server/drivers/claude.ts: registers the guard on every non-guest Claude turn, with or without the hook integration, matcher Bash|PowerShell|Monitor. Adds disableAllHooks: false so a project .claude/settings.json cannot switch it off, and sets ELECTRON_RUN_AS_NODE for the packaged app.
  • server/proxy-paths.ts, scripts/bundle-server.mjs: ship the helper in the packaged app.
  • server/browser/service.ts: the "browser could not start" message now says to retry once and not to open another browser.

Opt-out: set OMB_ALLOW_EXTERNAL_BROWSER=1 in the server's own environment. It is decided in claude.ts, not in the hook, because a bot's project settings env reaches the hook process.

Why

The intent is to stop bots from taking the person's focus by launching a desktop browser from the shell when the panel browser does not work. Prompt wording alone cannot guarantee this; under Full access the approval broker is skipped, but PreToolUse hooks still run, so the hook is the one place that holds in every permission mode.

Evidence caveat (from the review after this was written): in 14 days of bot transcripts, no case of "panel browser failed, then the bot opened Chrome with open -a" was found. The Chrome windows that did appear came from the social team's Chrome launches, MausBot's Chrome launches and BankXDev opening a PR link with open. Replaying 13,684 real shell commands from those 14 days through the guard blocked 11 (7 distinct); all were real browser launches except one false positive (a python heredoc that edited the guard's own test file). This guard is therefore a backstop, not the fix for the most common source below.

Before / After (real Claude Code 2.1.322, --permission-mode bypassPermissions, same prompt: run xdg-open https://example.invalid)

Before (no guard hook): the command ran.

Exit code 127
(eval):1: command not found: xdg-open

(xdg-open does not exist on this macOS host; on a machine that has it, or with open, the browser would have opened.)

After (guard hook in --settings): denied before it ran, and the model stopped without retrying.

PreToolUse:Bash hook error: OpenMausBot blocked this command: it opens a browser window on the person's desktop and takes their focus. Use your own browser tools (agent_browser_*) instead. If they fail, retry once, then stop and tell the person what failed and what you needed. ...

Known limits and what changes for users

  • The most common real focus-grabber is not covered. Over the 14 days, the biggest source was the social team's python3 scripts/ig_login_open.py, which opens a headed Chrome by default from inside a script file. The guard cannot see inside script files. Making those scripts headless by default is the follow-up that removes the cause.
  • Behavior change for the social team, and it is inconsistent. Starting a login Chrome straight from the shell (nohup ".../Google Chrome" --user-data-dir=... threads.com/login) and osascript ... "Google Chrome" to activate are now blocked, while the same thing done through a script (account_browser.py run, ig_login_open.py --keep-open) still passes. A person-visible login window started from the shell is therefore blocked; people relying on it must know.
  • The off switch is app-wide. OMB_ALLOW_EXTERNAL_BROWSER=1 is read from the server's environment, applies to every bot at once, and needs an app restart to change. There is no per-bot exception yet.
  • Only shell tools (Bash, PowerShell, Monitor) on the Claude engine. A user-added MCP server that opens a headed browser, or cua-driver, is not covered.
  • Not visible to the hook: variables (URL=...; open "$URL", B=open; $B), base64, xargs open, timeout/gtimeout wrappers, find -exec open, tmux/screen, perl/JXA/subprocess one-liners, and tools that open the default browser themselves (gh browse, gh pr view --web, vite --open, storybook dev). This is a guard against the common fallback, not a sandbox.
  • Known false positives (none seen in the 14-day replay): osascript ... "Xcode" to activate / display dialog "Ready to launch" are blocked because any activate/launch word counts, and the deny message says "browser"; open -a "Visual Studio Code" index.html, open -R report.html, open -e page.html are blocked by the .html rule.
  • open -g is allowed because it does not bring the app forward; actual focus behaviour was not measured.
  • Not run in the packaged Electron app; the Monitor deny was verified in code and unit tests, not in a real Claude CLI run; Windows untested.

Checklist

  • pnpm typecheck and the relevant tests pass locally (the unrelated e2e above fails on main too)
  • Server behavior changes come with tests
  • No dist-server/ edits
  • macOS-only code is platform-gated; no shell: true / cmd.exe string-building
  • No secrets in logs, responses, events, or argv

… desktop

A bot whose own browser failed could fall back to launching Chrome through
the shell, AppleScript or a script, which takes the person's focus. A
PreToolUse hook now denies those Bash/PowerShell/Monitor commands in every
permission mode (Full access included, where the approval broker is skipped)
and tells the bot to use its own browser tools, retry once, then report.

- server/hooks/browser-launch-guard.ts: tokenizer-based verdict (open, xdg-open,
  browser binaries, osascript activate/open location, interpreters, headed
  playwright); --headless, open -g and read-only osascript pass
- server/hooks/omb-browser-guard.ts: hook entry, fail-open
- claude.ts: registered for non-guest turns, disableAllHooks:false so a
  project setting cannot switch it off, opt-out only from the server env
  OMB_ALLOW_EXTERNAL_BROWSER=1
- browser/service.ts: start-failure message says not to open another browser
@zereight
zereight merged commit a927a80 into main Nov 14, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant