Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(cli): hand device-auth URLs to the browser without a shell - #2567

Open
thymikee wants to merge 2 commits into
mainfrom
fix/device-auth-browser-launch
Open

fix(cli): hand device-auth URLs to the browser without a shell#2567
thymikee wants to merge 2 commits into
mainfrom
fix/device-auth-browser-launch

Conversation

@thymikee

@thymikee thymikee commented Sep 13, 2026

Copy link
Copy Markdown
Member

Summary

agent-device auth login opened the device-auth verification URI on Windows with cmd /c start "" <url>. cmd /c re-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/https only, 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.ts into src/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 a host-execution.ts test util for platform mocking and spawn capture.

Closes #2526

Validation

Head 5c20b12f11: pnpm check:affected --run passed, pnpm test:unit passed (1283 files, 9886 tests), as did check:quick (lint + typecheck), check:layering, check:di-seams, check:production-exports. The scripts/__tests__/eager-closure-budgets.test.ts entry probe for src/cli.ts passes again — its failure at 7cca9db4eb is what the second commit fixes.

Each new assertion was planted-and-caught: cmd /c start on win32 fails the two Windows launch tests plus the flow test; dropping the verificationUriComplete guard, 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 mocking process.platform and recording argv, which is what the issue calls for; no Windows host ran the real rundll32 handoff, which is why its exit status is ignored rather than trusted.

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.
@github-actions

github-actions Bot commented Sep 13, 2026

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
Installed (including dependencies) 4.52 MB 4.52 MB +777 B
Package (unpacked) 4.52 MB 4.52 MB +777 B
Package (download) 1.33 MB 1.33 MB +233 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 21.1 ms 22.1 ms +0.9 ms
CLI --help 60.7 ms 60.9 ms +0.1 ms

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.
@thymikee

Copy link
Copy Markdown
Member Author

No findings at 5c20b12. The auth flow validates the URLs before printing or launching them, and Windows passes the URL without cmd parsing. The platform-mocked coverage satisfies #2526; checks are green and this is ready for human review.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): open the device-auth URL on Windows without cmd /c

1 participant