Skip to content

Quote a list for cmd.exe itself the way it's quoted for a batch file - #51

Merged
HalRiveria-Bot merged 1 commit into
mainfrom
fix/cmd-exe-list-quoting
Nov 17, 2026
Merged

HalRiveria-Bot merged 1 commit into
mainfrom
fix/cmd-exe-list-quoting

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

What was wrong: batch-file quoting ("" for a quote, line breaks refused) only applied when FilePath ended in .bat or .cmd. cmd.exe itself given a list got the ordinary \" quoting, which cmd.exe doesn't honor. So -FilePath cmd.exe -Arguments @('/d', '/c', 'echo', 'a" & echo INJECTED & "') ran the second command, and an element holding & was split there (a&b ran b). A list is the natural way to pass a file name or user value, even though the README said to give cmd.exe /c one string.

What changed:

  • A FilePath of cmd or cmd.exe (any folder, any case, trailing dots ignored) gets the same quoting as a batch file. Like a batch file, an element with a line break is now an error for it.
  • The README and ConvertTo-PkArgumentString help say so. The README also says what's still out of reach: cmd.exe strips the quotes from a program path with spaces after /c, so for one of those, give it one string with /s. That was already true with the old quoting.

Tested: new harness assertions, all failing before the fix on 5.1:

  • cmd.exe /d /c <argv-printer> given the same list as the existing %* test (quotes, \", trailing backslashes, spaces, &) gets it through exactly. Before the fix a&b came out as [a].
  • The seven existing batch-file injection payloads through cmd.exe /d /c echo, under four spellings of the name (full path, cmd, CMD.EXE, upper case with a trailing dot). Before the fix 28 of 28 ran the injected command; now none, and every probe ran.
  • The same payload through Invoke-PkProcessBatch with FilePath = 'cmd.exe'.

The spaced-path limit was checked by hand: a list gave no output, and the one-string /s /c form worked. Full harness passes on Windows PowerShell 5.1 and PowerShell 7.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria-Bot
HalRiveria-Bot merged commit ee3ac50 into main Nov 17, 2026
2 checks passed
@HalRiveria-Bot
HalRiveria-Bot deleted the fix/cmd-exe-list-quoting branch November 17, 2026 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants