Repository navigation
feat(claude): refuse shell commands that open a browser window on the desktop - #28
Merged
Merged
Conversation
… 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
5 tasks done
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/evalnesting up to 4 levels). Refusesopen <url|page|-a browser>,xdg-open/gio open/wslview,start/explorer <url>, browser binaries without--headless,osascriptthat activates/opens/reopens/makes a window, interpreters that callwebbrowser.open,headless=Falseoropen -a "Google Chrome", and headedplaywright/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,claudeHookSettingsand the newbrowserGuardHookSettingsmoved out ofclaude.ts(file-size ratchet);claude.tsre-exports them.server/drivers/claude.ts: registers the guard on every non-guest Claude turn, with or without the hook integration, matcherBash|PowerShell|Monitor. AddsdisableAllHooks: falseso a project.claude/settings.jsoncannot switch it off, and setsELECTRON_RUN_AS_NODEfor 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=1in the server's own environment. It is decided inclaude.ts, not in the hook, because a bot's project settingsenvreaches 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 withopen. 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: runxdg-open https://example.invalid)Before (no guard hook): the command ran.
(
xdg-opendoes not exist on this macOS host; on a machine that has it, or withopen, the browser would have opened.)After (guard hook in
--settings): denied before it ran, and the model stopped without retrying.Known limits and what changes for users
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.nohup ".../Google Chrome" --user-data-dir=... threads.com/login) andosascript ... "Google Chrome" to activateare 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.OMB_ALLOW_EXTERNAL_BROWSER=1is 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.URL=...; open "$URL",B=open; $B), base64,xargs open,timeout/gtimeoutwrappers,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.osascript ... "Xcode" to activate/display dialog "Ready to launch"are blocked because anyactivate/launchword counts, and the deny message says "browser";open -a "Visual Studio Code" index.html,open -R report.html,open -e page.htmlare blocked by the.htmlrule.open -gis allowed because it does not bring the app forward; actual focus behaviour was not measured.Checklist
pnpm typecheckand the relevant tests pass locally (the unrelated e2e above fails onmaintoo)dist-server/editsshell: true/ cmd.exe string-building