fix(toolkit-lib): reject discovered Windows paths containing %VAR% - #1924
Open
iankhou wants to merge 2 commits into
Open
fix(toolkit-lib): reject discovered Windows paths containing %VAR%#1924iankhou wants to merge 2 commits into
iankhou wants to merge 2 commits into
Conversation
cmd.exe expands %VAR% even inside double quotes, and a cmd /c command line cannot reliably escape a percent (doubling only works in batch files). A filesystem-discovered path carrying a %...% reference spliced into the user's app command line would therefore be silently rewritten (an env var expanded into the path). quoteShellPart now refuses such a path loudly instead of executing something other than what is on disk. Split out of #1905, which now carries only the resolveExecutable (PATH-vs-cwd) hardening. Follow-up to #1763 / #1849.
iankhou
added a commit
that referenced
this pull request
Sep 1, 2026
The quoteShellPart %VAR% guard is an independent fix on the shell path and now lives in its own PR (#1924). This PR is scoped to the resolveExecutable (PATH-vs-cwd) hardening on the no-shell run() path.
3 tasks
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.
Follow-up to #1763 / #1849.
Summary
quoteShellPart()(toolkit-lib) — cmd.exe expands%VAR%even inside double quotes, and acmd /ccommand line (howrunUserCommandLinereaches the shell on Windows) cannot reliably escape a percent (doubling only works in batch files). A filesystem-discovered path carrying a%...%reference spliced into the user'sappcommand line would therefore be silently rewritten — an environment variable expanded into the path. It is now refused loudly (ToolkitError('UnsafeWindowsPath', ...)) rather than executing something other than what is on disk.Demonstration of the problem
Ran these commands on a Windows machine in
cmd.Testing
environment.test.tsforcingplatform=win32and asserting a discovered%VAR%path is rejected.This test demonstrates that given a %VAR% path on Windows, guessExecutable throws
UnsafeWindowsPathinstead of returning a quoted string. What it does NOT demonstrate is the problem itself - that cmd.exe actually expands %VAR% inside double quotes. However, we demonstrated that in the section "Demonstration of the problem" above.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.