Repository navigation
Conversation
The WSL bridge handed the URL to cmd.exe as a bare spawn argument: Node's Windows escaping quotes whitespace and quotes only, so an & in a query string reached cmd.exe unquoted and parsed as a command separator (arbitrary execution on the Windows host), while every such URL already silently failed to open. Refuse URLs carrying cmd.exe metacharacters before spawning (fail closed at the documented chokepoint) and quote the URL explicitly for the ones that remain. The hop itself stays: on WSL the shell.openExternal route resolves to the Linux browser, cmd.exe start is how the Windows default browser is reached.
Raw CRLF is stripped by the WHATWG URL parser before parsing, so it is not constructible on this route; keep it in the character class as defense-in-depth but out of the refusal assertions. Verified red on upstream external-open.ts (3 failures) and green with the fix; the whole electron vitest project for the three external-open files passes and tsc/eslint/prettier are clean.
Related to #88558 and #124314, which address the same WSL cmd.exe launch path with different mechanisms. This variant fails closed by rejecting metacharacters, including ordinary ampersand query URLs; maintainer selection is needed rather than duplicate closure. |
13 of 14 tasks
15 of 19 tasks
This branch has not been deployed
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.
What does this PR do?
Closes the cmd.exe command-separator hole on the WSL link-open path, and with it the silent open failure for any URL carrying
&(i.e. most query strings).The WSL path in
external-open.tsspawnscmd.exe /c start "" <url>. Node's Windows argument escaping quotes whitespace and quotes only, so an&(or|,<,>,^,%VAR%) inside the URL reached cmd.exe unquoted — reading as command-line syntax. Consequences: a URL likehttps://example.com/x&calcexecutescalc(command injection), and even a benign?a=1&b=2silently fails to open because everything after&becomes a second command.This PR refuses URLs containing the cmd.exe metacharacter class before any spawn (
{ ok: false, reason: 'invalid' }, no process, no notification), and quotes the URL that does reach cmd.exe. Raw\r\nis not constructible (the WHATWG URL parser strips tabs/newlines) but stays in the class as defense-in-depth. Metacharacter-free URLs — includingmailto:with query strings — keep working.Related Issue
Fixes #126939
Type of Change
Changes Made
apps/desktop/electron/external-open.ts: cmd.exe metacharacter class constant + pre-spawn refusal with log line; the spawned URL is double-quoted.apps/desktop/electron/external-open.test.ts: happy-path test pins the quoted URL; new tests cover the refused metacharacter matrix (spawn count 0) and a metacharacter-freemailto:still spawning.How to Test
cd apps/desktop && npx vitest run electron/external-open.test.ts&in its query string; confirm nothing spawns and the open is refused; a plain URL opens normally.Checklist
Code
external-open.test.ts)Documentation & Housekeeping
openExternaluntouched)