Skip to content

fix(claude): narrow the browser launch guard's false positives and unwrap timeout - #30

Merged
zereight merged 2 commits into
mainfrom
fix/browser-guard-followups
Nov 14, 2026
Merged

zereight merged 2 commits into
mainfrom
fix/browser-guard-followups

Conversation

@zereight

@zereight zereight commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changed

Follow-up to #28 (the PreToolUse guard that refuses shell commands which open a browser window on the person's desktop). It narrows three false positives and one cheap bypass that the final review of #28 found. Only server/hooks/browser-launch-guard.ts and its test change.

  • osascript: activate / launch / make new window|document|tab / reopen / frontmost ... to true are refused only when the script also names a browser (name or bundle id). open location and openLocation( (JXA) always reach the default browser, so they stay refused. tell application "Xcode" to activate and display dialog "Ready to launch" now pass.
  • open: a .html argument no longer counts when -a/-b names a non-browser app (open -a "Visual Studio Code" index.html) or when -R / -e / -t is used (Finder / text editor). A URL argument is still refused regardless of -a, and a browser named by -a/-b is still refused.
  • Zen / Dia: added to the browser lists (names Zen, Zen Browser, Dia; bundle ids app.zen-browser.zen, company.thebrowser.dia; Zen.app / Dia.app in scripts). The two relaxations above rely on the app being recognised as a browser, so an unlisted browser would have been let through (found by review on this Mac, where Zen is the default browser and Dia is installed). dialog, Media.app and Zenmap do not match.
  • timeout / gtimeout: unwrapped (flags, -s/-k values and one duration), so timeout 5 open https://example.com is judged like open https://example.com. Only the command it runs is judged, so timeout 5 grep open file passes.

Why

#28's review replayed 13,684 real shell commands from the last 14 days: 11 blocked, all genuine browser launches except one false positive. The cases fixed here did not occur in that replay, but are cheap to hit (Xcode/Simulator activate, opening an .html in an editor) or to dodge (timeout 5 open URL).

Known gaps this PR opens or leaves

  • The osascript narrowing needs the script to name a browser. A script that hides the name (System Events + frontmost of every process whose name contains "Chr" to true, or "Google Chr" & "ome") is not caught. Needs deliberate obfuscation; 0 occurrences in the 14-day replay.
  • osascript -e 'do shell script "open https://x"' passes on main and on this branch (the string is not fed back into the shell check). Candidate follow-up.
  • Recognising browsers by a name list means a newly installed browser is let through until it is added. The safer long-term shape is the reverse (allow known editors, treat unknown apps as browsers, or read the app's Info.plist for an http handler). Not done here.

Not in this PR

  • xargs: echo URL | xargs open gets its URL on stdin, so unwrapping xargs cannot see it, and ls *.pdf | xargs open would become a false positive.
  • Variables, find -exec, tmux/screen, perl/JXA/subprocess one-liners, and tools that open the default browser themselves (gh browse, vite --open): still not covered (same limits as feat(claude): refuse shell commands that open a browser window on the desktop #28).
  • A per-bot exception to OMB_ALLOW_EXTERNAL_BROWSER=1: needs a settings surface and a server-side decision point; separate design.
  • The social team's scripts/ig_login_open.py (headed by default): it exists so a person can see and complete a login, and it lives in the social team's folder, so it is not changed here.

How it was verified

  • pnpm typecheck clean (exit 0).
  • pnpm exec vitest run server/hooks server/drivers/claude.test.ts scripts/testing/file-size-ratchet.test.ts: 417 pass, 1 skipped, 1 fail. The one failure, claude.test.ts > lets a Bash call ask for up to two hours (BASH_MAX_TIMEOUT_MS expected 86400000, got 600000), fails identically on an unmodified origin/main (checked with the change stashed), so it is not caused by this PR.
  • Reviewer (DevilsAdvocate) replayed the same 13,684 commands (14-day batch pulled 2026-11-14 13:55) on the earlier revision of this branch: 0 newly blocked, 0 newly unblocked, the 11 genuine blocks (7 unique) unchanged. Not re-run after the Zen/Dia commit (that commit only adds names to the lists).

Before / After

Same inputs run through browserLaunchVerdict on main (Before) and on this branch (After).

Changed:

command Before (main a927a80) After
osascript -e 'tell application "Xcode" to activate' blocked allowed
osascript -e 'tell application "Simulator" to activate' blocked allowed
osascript -e 'display dialog "Ready to launch"' blocked allowed
osascript -l JavaScript -e 'Application("Finder").openLocation("https://x")' allowed blocked
open -a "Visual Studio Code" index.html blocked allowed
open -R report.html blocked allowed
open -e page.html blocked allowed
open -t page.html blocked allowed
timeout 5 open https://example.com allowed blocked
timeout 5s open https://example.com allowed blocked
gtimeout -k 1 5 open -a Safari allowed blocked
timeout --foreground -s KILL 10 open https://example.com allowed blocked

Zen and Dia (the first revision of this PR let these through; fixed in the last commit):

command Before (main a927a80) first revision After
osascript -e 'tell application "Zen" to activate' blocked allowed blocked
osascript -e 'tell application "Dia" to activate' blocked allowed blocked
osascript -e 'tell application id "app.zen-browser.zen" to activate' blocked allowed blocked
osascript -e 'tell application id "company.thebrowser.dia" to activate' blocked allowed blocked
open -a Zen index.html / open -a Dia index.html / open -a 'Zen Browser' index.html blocked allowed blocked
open -b app.zen-browser.zen index.html blocked allowed blocked
timeout 5 open -a Dia index.html allowed allowed blocked
open -a Media index.html, open -a Zenmap index.html blocked allowed allowed

Unchanged (regression guard; still refused or still allowed):

command Before (main a927a80) After
osascript -e 'tell application "Google Chrome" to activate' blocked blocked
osascript -e 'tell application "Safari" to make new document' blocked blocked
osascript -e 'tell application id "com.google.Chrome" to activate' blocked blocked
osascript -e 'open location "https://example.com"' blocked blocked
osascript -e 'tell application "System Events" to set frontmost of process "Safari" to true' blocked blocked
osascript -e 'tell application "System Events" to get name of every window of process "Google Chrome"' allowed allowed
open -a "Google Chrome" page.html blocked blocked
open -a Safari blocked blocked
open ./report.html blocked blocked
open https://example.com blocked blocked
open -a Finder https://example.com blocked blocked
open -a Slack slack://channel allowed allowed
open -R https://example.com blocked blocked
timeout 5 grep open file allowed allowed
timeout 5 curl https://example.com allowed allowed
timeout 5 sleep 1 allowed allowed
timeout $T open https://example.com allowed allowed
echo https://example.com | xargs open allowed allowed

Checklist

  • pnpm typecheck and the relevant tests pass locally (the one unrelated failure above also fails on main)
  • 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

tao.exe added 2 commits November 14, 2026 14:18
…wrap timeout

osascript is refused for activate/launch/make new window only when the
script names a browser (open location still always); open -a <non-browser>,
-R, -e and -t no longer count a .html argument as a browser launch; timeout
and gtimeout are unwrapped so 'timeout 5 open https://...' is judged.
Narrowing osascript activate and open -a <app> page.html relies on the app being
named a browser, so a browser missing from the list slipped through. Zen and Dia
were missing; both are installed on the maintainer's Mac.
@zereight
zereight merged commit eb73e8f into main Nov 14, 2026
14 of 25 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