Repository navigation
fix: decode escaped Windows executable tokens - #166
Merged
Merged
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Sep 25, 2026
nkolev92
previously approved these changes
Sep 28, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
nkolev92
approved these changes
Oct 1, 2026
jeffkl
approved these changes
Oct 9, 2026
Merged
This was referenced Oct 14, 2026
martinrrm
pushed a commit
that referenced
this pull request
Oct 21, 2026
🤖 I have created a release *beep* *boop* --- ## [10.0.1](v10.0.0...v10.0.1) (2026-10-12) ### Bug Fixes * [`e823469`](e823469) [#166](#166) decode escaped Windows executable tokens (#166) (@martinrrm, @Copilot) ### Chores * [`8d804b6`](8d804b6) [#161](#161) bump @npmcli/eslint-config from 6.0.1 to 7.0.0 (#161) (@dependabot[bot]) * [`e19bfab`](e19bfab) [#162](#162) bump @npmcli/template-oss from 5.1.0 to 5.1.1 (#162) (@dependabot[bot], @npm-cli-bot) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
martinrrm
added a commit
that referenced
this pull request
Oct 21, 2026
Actual Windows CI checks out YAML with CRLF. Normalize workflow text before matching LF-delimited input and Publish-step blocks, and exercise both LF and CRLF fixtures on every platform. The new CRLF cases reproduce the original CI failures before normalization. Leave the published #166 backport, pinned which API, generated workflows, Node matrix and release configuration unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 330b549f-83dd-4218-81b7-003cc008f869
martinrrm
added a commit
that referenced
this pull request
Oct 21, 2026
Actual Windows CI checks out YAML with CRLF. Normalize workflow text before matching LF-delimited input and Publish-step blocks, and exercise both LF and CRLF fixtures on every platform. The new CRLF cases reproduce the original CI failures before normalization. Leave the published #166 backport, pinned which API, generated workflows, Node matrix and release configuration unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 330b549f-83dd-4218-81b7-003cc008f869
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.
Summary
Decode an already quoted and caret-escaped executable token before using it for Windows executable lookup.
This is a supporting change for npm/cli#10044. That proposal protects an executable name before placing it in a command interpreted by
cmd.exe.promise-spawnmust still identify the protected executable as a.cmdor.batshim so it can apply the existing extra escaping required for batch-file arguments.Why this is needed
There are two distinct representations of the executable:
cmd.exe, and kept unchanged in the final command string.which.sync()can resolve the executable and determine whether it is a batch shim.For example, a caller may pass this protected executable token:
The existing parser derives the lookup value directly from that text:
That is not an executable name that
which.sync()can resolve. If lookup fails,promise-spawnmay not recognize that the command is a.cmdshim, sodoubleEscaperemains false.The updated parser derives this lookup-only value instead:
The original
^"tool.cmd^"token is still retained in the command sent tocmd.exe; only the temporary value used for executable detection is decoded.Why batch shims need detection
promise-spawnalready distinguishes native executables from.cmdand.batshims:A batch shim causes its arguments to pass through an additional
cmd.exeparsing layer. The existingescape.cmd(arg, doubleEscape)implementation therefore adds another level of caret escaping whendoubleEscapeis true.Using the safe argument
hello worldas an example:^"hello^ world^".cmd/.batshim^^^"hello^^^ world^^^"If an escaped
tool.cmdtoken cannot be resolved, the first form may be selected even though the second form is required for the batch shim.Data flow with npm CLI
The related npm CLI proposal has this flow on Windows:
This PR implements only the lookup step. It does not decide which executable names are valid, add shell quoting to arbitrary commands, or decode the command that is executed.
Changes
"as acmd.exequote delimiter; single quotes have no quoting semantics incmd.exe.which.sync()..cmd/.batargument double-escaping behavior.Before and after
tooltooltooltool"tool.cmd""tool.cmd"tool.cmd"tool.cmd"^"tool.cmd^"^"tool.cmd^"tool.cmd^"tool.cmd^"^"two^ words.cmd^"^"two^ words.cmd^"two words.cmd^"two^ words.cmd^"Tests
Added mock-based regression coverage confirming that:
.cmdshim is recognized.cmd.exeretains the protected executable token.The tests validate command construction and executable lookup without executing an injection payload.
Related change