Repository navigation
fix(claude): narrow the browser launch guard's false positives and unwrap timeout - #30
Merged
Merged
Conversation
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.
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
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.tsand its test change.activate/launch/make new window|document|tab/reopen/frontmost ... to trueare refused only when the script also names a browser (name or bundle id).open locationandopenLocation((JXA) always reach the default browser, so they stay refused.tell application "Xcode" to activateanddisplay dialog "Ready to launch"now pass..htmlargument no longer counts when-a/-bnames a non-browser app (open -a "Visual Studio Code" index.html) or when-R/-e/-tis used (Finder / text editor). A URL argument is still refused regardless of-a, and a browser named by-a/-bis still refused.Zen,Zen Browser,Dia; bundle idsapp.zen-browser.zen,company.thebrowser.dia;Zen.app/Dia.appin 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.appandZenmapdo not match.-s/-kvalues and one duration), sotimeout 5 open https://example.comis judged likeopen https://example.com. Only the command it runs is judged, sotimeout 5 grep open filepasses.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.htmlin an editor) or to dodge (timeout 5 open URL).Known gaps this PR opens or leaves
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 onmainand on this branch (the string is not fed back into the shell check). Candidate follow-up.Info.plistfor an http handler). Not done here.Not in this PR
xargs:echo URL | xargs opengets its URL on stdin, so unwrappingxargscannot see it, andls *.pdf | xargs openwould become a false positive.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).OMB_ALLOW_EXTERNAL_BROWSER=1: needs a settings surface and a server-side decision point; separate design.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 typecheckclean (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_MSexpected86400000, got600000), fails identically on an unmodifiedorigin/main(checked with the change stashed), so it is not caused by this PR.Before / After
Same inputs run through
browserLaunchVerdictonmain(Before) and on this branch (After).Changed:
osascript -e 'tell application "Xcode" to activate'osascript -e 'tell application "Simulator" to activate'osascript -e 'display dialog "Ready to launch"'osascript -l JavaScript -e 'Application("Finder").openLocation("https://x")'open -a "Visual Studio Code" index.htmlopen -R report.htmlopen -e page.htmlopen -t page.htmltimeout 5 open https://example.comtimeout 5s open https://example.comgtimeout -k 1 5 open -a Safaritimeout --foreground -s KILL 10 open https://example.comZen and Dia (the first revision of this PR let these through; fixed in the last commit):
osascript -e 'tell application "Zen" to activate'osascript -e 'tell application "Dia" to activate'osascript -e 'tell application id "app.zen-browser.zen" to activate'osascript -e 'tell application id "company.thebrowser.dia" to activate'open -a Zen index.html/open -a Dia index.html/open -a 'Zen Browser' index.htmlopen -b app.zen-browser.zen index.htmltimeout 5 open -a Dia index.htmlopen -a Media index.html,open -a Zenmap index.htmlUnchanged (regression guard; still refused or still allowed):
osascript -e 'tell application "Google Chrome" to activate'osascript -e 'tell application "Safari" to make new document'osascript -e 'tell application id "com.google.Chrome" to activate'osascript -e 'open location "https://example.com"'osascript -e 'tell application "System Events" to set frontmost of process "Safari" to true'osascript -e 'tell application "System Events" to get name of every window of process "Google Chrome"'open -a "Google Chrome" page.htmlopen -a Safariopen ./report.htmlopen https://example.comopen -a Finder https://example.comopen -a Slack slack://channelopen -R https://example.comtimeout 5 grep open filetimeout 5 curl https://example.comtimeout 5 sleep 1timeout $T open https://example.comecho https://example.com | xargs openChecklist
pnpm typecheckand the relevant tests pass locally (the one unrelated failure above also fails onmain)dist-server/editsshell: true/ cmd.exe string-building