Skip to content

Windows: cmd.exe re-reading a .cmd CLI's arguments is can't tell (#168) - #185

Merged
paureis merged 5 commits into
mainfrom
fix/168-cmd-reread
Nov 5, 2026
Merged

paureis merged 5 commits into
mainfrom
fix/168-cmd-reread

Conversation

@paureis

@paureis paureis commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Closes #168 (PR 4 of the fail-closed design, docs/superpowers/specs/2026-11-04-fail-closed-design.md).

The bug. On Windows, az and npm-installed CLIs are .cmd files, and cmd.exe re-reads their arguments. In PowerShell, az group list --query 'x&kubectl' also runs kubectl, and --subs^cription other reaches the CLI as --subscription other. cloudpin saw one az call with one value.

A correction to the issue: 'x&kubectl get pods' has spaces, so PowerShell 5.1 quotes it and kubectl doesn't run. The real forms are 'x&kubectl', 'a b"&kubectl get pods&"c' and --%.

The fix: "can't tell", not a split (owner decision). Only on Windows, read as PowerShell or with a typed .cmd/.bat, when the CLI resolves to a .cmd or .bat: rebuild the command line as PowerShell 5.1 does, and scan it with cmd.exe's quote toggle. An unquoted &, |, <, >, ^ or ), a newline or carriage return anywhere, or %NAME% anywhere stops. The message names the character class, never a value.

  • gh.exe isn't a .cmd, so gh --jq filters are unaffected. That test is what keeps this cheap: without it, 452 real lines would stop.
  • A .ps1 beside the .cmd keeps the rule silent, because PowerShell 5.1 runs the .ps1, or refuses it by policy, and never reaches cmd.exe. npm writes both, so this covers npm installs.
  • Git Bash runs the extensionless script, so the rule applies there only to a typed .cmd.

Evidence

  • npm run typecheck exit 0; npx vitest run: 4493 passed, 19 skipped. 153 new tests, seen failing first.
  • 53 mutations: 51 killed on the first run, 1 killed after correcting a stub, 1 equivalent and removed. One more here, newline rule off: 4 tests fail.
  • 37 forms in real PowerShell 5.1 and Git Bash, with printers shaped like az.cmd and npm's vercel.cmd plus a compiled gh.exe: main allowed all 37, so the check can fail, and the branch matches what each printer really got.
  • No measurable time cost: 20 runs each, median 213 ms against 220 ms for a clean line. The line is scanned first, so most calls never look at PATH.
  • On 31,770 of the owner's real commands (counts only): 0 stops read by each tool's real shell; 6 of 4,885 calls if every line is read as PowerShell.

Not tested

pwsh (not installed; 7.3+ comes from about_Preference_Variables, and its quote rule and .ps1 precedence are unmeasured). No real CLI.

Left open

An unguarded .cmd isn't read. A value only known at run time could hold & (--query $env:Q) and passes unless it's a target flag.

🤖 Generated with Claude Code

paureis and others added 5 commits November 4, 2026 23:16
On Windows, read as PowerShell (or with a .cmd or .bat name typed), when the CLI
resolves to such a file: rebuild the command line as the shell does, scan it with
cmd.exe's quote toggle, and an unquoted & | < > ^ ), a newline or %NAME% is "can't
tell", naming the class and no value. A guarded CLI the words name stops too, as
cmd.exe may run it. gh.exe and other .exe CLIs are untouched, a .ps1 beside the .cmd
never reaches cmd.exe, and Linux and macOS are untouched. The line is scanned first,
so most calls never look at PATH, and nothing is spawned for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests for what the first commit already does: a URL with & after a variable, a word
bash splits, and --% text that stays with its own statement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CHANGELOG under Security, ROADMAP's line says done, AGENTS has the new file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A mutation that left out the \" survived, and rightly: cmd.exe toggles on the quote
whatever is before it, and an empty word holds nothing it acts on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paureis
paureis merged commit 353dc65 into main Nov 5, 2026
4 checks passed
@paureis
paureis deleted the fix/168-cmd-reread branch November 5, 2026 04:30
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.

Windows: cmd.exe re-reads the arguments of .cmd CLIs (az.cmd, npm shims), so & or ^ in a value changes the call

1 participant