fix(auth): caret-escape cmd metacharacters when opening the browser on WSL#61
Merged
Merged
Conversation
…n WSL
`openViaCmdExe` wrapped the URL in double quotes to stop `&` from splitting the
`cmd.exe /c start` command line. Under WSL that doesn't work: the interop layer
re-quotes argv entries itself, mangling the literal quotes, so `&` leaks through
and acts as a statement separator — only the prefix up to the first `&` reaches
`start`, and Windows tries to open that fragment as a path ("Windows cannot find
'\https://…'"). OAuth authorize URLs (several `&`, percent-encoded params) hit
this every time.
Two compounding bugs:
- The surrounding quotes don't survive WSL interop, so `&` was never protected.
- `url.replaceAll('%','%%')` does not collapse on the `cmd /c` command line (only
inside batch files), so it would have corrupted every `%HH` byte even when the
command did run.
Fix: caret-escape cmd's metacharacters (`& | < > ^ ( ) "`) — which survives
interop since there are no quotes to mangle — and leave `%` alone (OAuth URLs are
`%HH`, which never matches `%NAME%` env-expansion). Extracted as a testable
`escapeUrlForCmd`; verified the round-trip through a real `cmd.exe` on WSL.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
doistbot
reviewed
Jun 5, 2026
Member
doistbot
left a comment
There was a problem hiding this comment.
Thank you Scott for thoroughly diagnosing and addressing the WSL browser-open bug 🤗.
Few things worth tightening:
- Although caret-escaping handles command metacharacters well,
cmd.exewill still treat certain valid percent-encoded sequences (like%C3%in%C3%A9) as environment variables; bypassingcmd.exeentirely to launch the browser would be a safer way to prevent URL corruption on WSL.
I also included a few optional follow-up notes in the details below.
Optional follow-up note (1)
- [P3] src/auth/flow.test.ts:527: These assertions duplicate the escaping logic checks already covered by the dedicated
escapeUrlForCmdtest below. Since you are already assertingexpect(args).toEqual(['/c', 'start', '""', escapeUrlForCmd(url)])on line 524, lines 527-532 can be removed to keep this test strictly focused on the routing behavior.
Addresses review: caret-escaping cmd metacharacters still left `%` exposed — a percent-encoded multi-byte UTF-8 byte like `%C3%A9` (é) contains `%C3%`, which `cmd /c` would treat as `%VAR%` env-expansion and mangle. Since runOAuthFlow is public API for custom AuthProviders, that's a real hazard, not just a built-in concern. Bypass the shell entirely: launch via `rundll32.exe url.dll,FileProtocolHandler <url>`. CreateProcess hands the single argv to the protocol handler verbatim — no cmd parsing pass — so neither `&` (statement separator) nor `%HH` (env-expansion) can corrupt the URL, and there's no fragile escaping to maintain. Drops the now-unneeded escapeUrlForCmd helper. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
doist-release-bot Bot
added a commit
that referenced
this pull request
Jun 5, 2026
## [0.25.1](v0.25.0...v0.25.1) (2026-06-05) ### Bug Fixes * **auth:** caret-escape cmd metacharacters when opening the browser on WSL ([#61](#61)) ([9abcfea](9abcfea))
Contributor
|
🎉 This PR is included in version 0.25.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Symptom
On WSL,
<cli> auth login(any DCR/OAuth consumer) pops a Windows dialog:instead of opening the browser. The URL is truncated at the first
&and treated as a file path.Root cause
openViaCmdExeopens the browser viacmd.exe /c start "" "<url>", wrapping the URL in double quotes to stop&from splitting the command line. Under WSL that doesn't work: the interop layer re-quotes argv entries itself, mangling the literal quotes, so&leaks through tocmd.exeas a statement separator. Only the prefix up to the first&reachesstart; Windows then tries to open that fragment as a path.Two compounding bugs, both confirmed with a real
cmd.exeon WSL:&was never actually protected (cmd reported'response_type' is not recognized…for each&-separated param).url.replaceAll('%','%%')does not collapse on thecmd /ccommand line (only inside batch files), so%3A→%%3Awould have corrupted every percent-encoded byte even when the command did run.Only OAuth consumers that override
openBrowser(e.g. todoist-cli, which routes through theopenpackage) dodged this; consumers on the default opener hit it every login.Fix
Caret-escape cmd's metacharacters (
& | < > ^ ( ) ") instead of quoting — caret escaping survives WSL interop because there are no quotes for it to mangle — and leave%untouched (OAuth URLs are RFC 3986%HH, which never matches cmd's%NAME%env-expansion; there's no command-line caret-escape for%, and doubling corrupts%HH).Extracted as a pure, exported
escapeUrlForCmdand unit-tested. Verified end-to-end against a realcmd.exeon WSL: the escaped string round-trips to the exact URL (carets stripped),&is protected,%HHpreserved.Tests
%%behavior).escapeUrlForCmdunit test (per-metacharacter escaping + percent-encoding round-trip).🤖 Generated with Claude Code