Commit 9abcfea
fix(auth): caret-escape cmd metacharacters when opening the browser on WSL (#61)
* fix(auth): caret-escape cmd metacharacters when opening the browser on 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>
* fix(auth): open the WSL browser via rundll32 instead of cmd.exe
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>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 7718e11 commit 9abcfea
2 files changed
Lines changed: 31 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
498 | 496 | | |
499 | 497 | | |
500 | 498 | | |
| |||
510 | 508 | | |
511 | 509 | | |
512 | 510 | | |
513 | | - | |
| 511 | + | |
514 | 512 | | |
515 | 513 | | |
516 | 514 | | |
| |||
522 | 520 | | |
523 | 521 | | |
524 | 522 | | |
525 | | - | |
526 | | - | |
527 | | - | |
528 | | - | |
529 | | - | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
530 | 528 | | |
531 | 529 | | |
532 | 530 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
484 | 484 | | |
485 | 485 | | |
486 | 486 | | |
487 | | - | |
488 | | - | |
489 | | - | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
490 | 490 | | |
491 | 491 | | |
492 | 492 | | |
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
519 | 520 | | |
0 commit comments