fix(cli): hand device-auth URLs to the browser without a shell - #2567
Open
thymikee wants to merge 2 commits into
Open
fix(cli): hand device-auth URLs to the browser without a shell#2567thymikee wants to merge 2 commits into
thymikee wants to merge 2 commits into
Conversation
Windows opened the device-auth verification URI with `cmd /c start "" <url>`, and `cmd /c` re-tokenizes its argument string even when spawned as argv, so `&`, `^`, or `|` in a URL from the auth response could run an extra command. Launch through `rundll32.exe url.dll,FileProtocolHandler <url>` instead, with the URL as one inert argv entry on every platform, and refuse a verification URI that is not an http(s) URL free of control and format characters while the start response is still being validated, so neither the launcher nor the terminal sees one. The launcher decision and the URL guard move into src/cli/browser-launch.ts, which also stops treating a launcher's exit status as a handoff report on Windows.
Size Report
Startup median (7 runs, lower is better):
|
The unit-ci coverage gate ratchets the modules `src/cli.ts` evaluates on import against the merge-base, and the launcher module arrived inside that closure through `auth-session.ts`, taking the entry from 295 modules to 296. `src/cli.ts` may not grow, so the device-auth flow now reaches the launcher at its call sites, the same shape the command router already uses, and opening a browser stays off the startup path entirely.
Member
Author
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.
Summary
agent-device auth loginopened the device-auth verification URI on Windows withcmd /c start "" <url>.cmd /cre-tokenizes its argument string even when spawned as argv, so&,^, or|in a URL taken from the auth response could run an extra command.Windows now launches
rundll32.exe url.dll,FileProtocolHandler <url>, and every platform passes the URL as one inert argv entry — no shell anywhere. The verification URIs are checked as the start response is validated:http/httpsonly, and no control or format characters, so neither the launcher nor the terminal sees anything else. No host allowlist.The launcher decision and the URL guard moved out of
src/cli/auth-session.tsintosrc/cli/browser-launch.ts, which the auth flow reaches at its call sites so CLI startup keeps evaluating what it did before, and which stops reading a launcher's exit status as a handoff report on Windows, where a successful handoff can exit non-zero. Tests record the argv a flow would have spawned through the existing command-executor seam. Five files: the two sources, their tests, and ahost-execution.tstest util for platform mocking and spawn capture.Closes #2526
Validation
Head
5c20b12f11:pnpm check:affected --runpassed,pnpm test:unitpassed (1283 files, 9886 tests), as didcheck:quick(lint + typecheck),check:layering,check:di-seams,check:production-exports. Thescripts/__tests__/eager-closure-budgets.test.tsentry probe forsrc/cli.tspasses again — its failure at7cca9db4ebis what the second commit fixes.Each new assertion was planted-and-caught:
cmd /c starton win32 fails the two Windows launch tests plus the flow test; dropping theverificationUriCompleteguard, the\p{Cf}class, the launcher's own URL check, or the Windows exit-status tolerance each fails exactly its test. The Windows branch is exercised on macOS by mockingprocess.platformand recording argv, which is what the issue calls for; no Windows host ran the realrundll32handoff, which is why its exit status is ignored rather than trusted.