fix(oauth): open the sign-in URL without a command interpreter on Windows
What and why
e2e login opens the sign-in URL in the user's browser. On Windows it did that with cmd /c start "" <url>, and the only character it escaped was &. That is fine for a URL the runner built, but the URL is not always one the runner built. In the device flow it is the verification_uri that the provider's own HTTP response carries (packages/e2e/src/oauth/device-code.ts:111), and the schema accepts it as a plain string, with no check on its shape. The provider's response is external input, and cmd reads |, &, ^, <, >, and % inside a URL as command syntax. A URL that carries a pipe makes cmd run whatever follows it, and a single ^ cancels the & escape the code applied, so a URL carrying ^& was enough to run a command of the sender's choosing on the machine that ran e2e login.
Three providers use the device flow, so their sign-in URLs took that path: GitHub Copilot, SuperGrok, and OpenCode Console. The ChatGPT flow builds its own authorize URL with URLSearchParams inside the runner (packages/e2e/src/oauth/providers/openai.ts:181), so it was never exposed.
The fix keeps the URL out of any command interpreter and narrows what the runner opens at all. The URL now goes to the default handler for its scheme as one plain argument, and only http: and https: are opened. A URL with any other scheme is left to the user, who reads the link the CLI prints and opens it themselves, which is what the CLI already did whenever the browser did not come up.
Per CONTRIBUTING.md this belongs through SECURITY.md rather than the issue tracker, so I have not opened an issue. If a coordinated advisory is wanted, I can send the details to security@tester.army.
What changed
packages/e2e/src/oauth/browser.tsis new and holdsbrowserCommand(platform, url). On Windows it returnsrundll32 url.dll,FileProtocolHandlerwith the URL as its second argument, so nothing reads the URL as a command line. macOS keepsopenand Linux keepsxdg-open, both of which already took the URL as a plain argument. The platform is a parameter, so the argv is testable on any machine.- The builder opens only
http:andhttps:URLs (packages/e2e/src/oauth/browser.ts:23,:40-47). Anything else returns undefined, and the CLI does not open it. packages/e2e/src/oauth/cli.ts:266calls the builder and spawns what it returns. Thecmd /c startcall and the^&escape are gone.packages/e2e/tests/unit/oauth/browser.test.tsis new, with six tests over the argv, the URL arriving unchanged, and the scheme rule.docs/reference/security.mdx:93records the rule in the navigation table, next to the schemes the runner's own navigation accepts.- The changeset is a patch for
e2e, sincee2e loginships in the published package.
| main | this branch |
|---|---|
Windows opener: cmd /c start "" <url>, with & written as ^& | Windows opener: rundll32 url.dll,FileProtocolHandler <url>, the URL as one argument |
A URL carrying | makes cmd run what follows the pipe | the URL reaches the handler unchanged |
A URL carrying ^& cancels the escape, and cmd runs the rest | the URL reaches the handler unchanged |
A file:, data:, or javascript: URL is opened by the shell | the CLI prints the URL and does not open it |
Verified
Ran it locally: yes
- The new unit test was written first and run against the old behavior, extracted verbatim into the new module. It failed 4 of 6 on exactly the three things this fixes, and passed 6 of 6 after the change.
before: 4 failed | 2 passed (6)
expected 'cmd' not to be 'cmd'
expected 'https://example.com/login/device?code…' to be 'https://example.com/login/device?code…' (the ^& escape had changed the URL)
expected { Object (command, args) } to be undefined (a file: URL was opened)
after: 6 passed (6)
- The injection was reproduced on Windows in the exact shape the old code used, and then shown to be gone with the new one. The payload is a URL that carries a pipe and writes a file:
old: cmd /c start "" x|set>p1.txt -> p1.txt written, the injected command ran
old: cmd /c start "" x^&set>p2.txt -> p2.txt written, the caret cancelled the escape
new: rundll32 url.dll,FileProtocolHandler https://example.com/login/device?code=x|set>pwned.txt
the program receives one argument, "https://example.com/login/device?code=x|set>pwned.txt", and no file is written
-
The browser still opens.
rundll32 url.dll,FileProtocolHandler https://example.com/exits 0 with no output and no error, so the sign-in page comes up as before. -
The unit suite of
packages/e2eon the branch, and on the same tree with the change stashed:
main: Test Files 20 failed | 173 passed (193) Tests 47 failed | 2851 passed | 25 skipped (2923)
branch: Test Files 20 failed | 174 passed (194) Tests 46 failed | 2858 passed | 25 skipped (2929)
The set of failing files is the same 20 in both runs. The three tests that differ flake in both directions, two telemetry tests that passed on the branch and one managed process test that failed on it, so they are the timing flakes this suite has on Windows rather than a change in behavior. The branch adds the new file and its 6 passing tests.
oxlintreports 0 warnings and 0 errors on the three touched files, andtsc --noEmitinpackages/e2eis clean.fallow dead-codereports the same 2 files and the same 22 class members before and after the change, so the new module is not dead code.node scripts/check-error-codes.tsreports 86 error codes in source, all documented.node scripts/check-peer-ranges.tspasses, andnode scripts/check-changeset-bumps.tsreports "34 pending, none an unannounced 0.x minor or major" with this changeset in the set.check-install-scriptsdid not run here, because this machine's install is partial. It runs inspec.ymlon every pull request.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.