# cross-spawn: Command injection on Windows when spawning batch files

cross-spawn escaped batch-file arguments for cmd.exe only for node_modules/.bin shims, so crafted args to npm.cmd or user .bat files broke out of quotes and ran arbitrary commands on Windows.

- Payout: Research
- Severity: critical
- Program: cross-spawn
- Found by: mohd-akram
- Disclosed: 2026-12-01
- CVE: CVE-2026-137199
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-ghv9-86vm-4v8m
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-ghv9-86vm-4v8m
- Tags: area:oss domain:oss impact:rce kind:research platform:ghsa sev:critical tech:nodejs tech:windows technique:incomplete-fix technique:parser-differential vuln:command-injection

**Target:** npm library cross-spawn spawning batch files via cmd.exe on Windows
**Root cause:** cross-spawn escaped arguments for cmd.exe's second parse only when the batch file was an npm cmd-shim in node_modules/.bin; other batch files forwarding args with %* re-parse the escaped string, letting quotes break out. Trailing dots/spaces bypassed batch detection, and %VAR%/!VAR! expansion edge cases existed.
**Steps:**
1. On Windows, call `spawn.sync('npm', ['" & calc & "'])` via cross-spawn
2. cross-spawn detects npm as a batch file and routes through cmd.exe, escaping only for node_modules/.bin shims
3. npm.cmd forwards args with %*, cmd.exe re-parses the argument
4. The `"` closes the quote and `& calc &` executes calc.exe
**How found:** Researcher noticed cross-spawn's escaping special-cased only node_modules/.bin cmd-shims for cmd.exe's double parse, then tested other batch files like npm.cmd that forward args with %*, plus trailing-dot/space detection bypass and %VAR^%/!VAR! expansion quirks.
**Exploitation:** Any app passing untrusted input as arguments to a batch-file command (npm.cmd, global shims, user .bat) on Windows lets an attacker inject `" & <command> & "` to run arbitrary commands under the app's privileges.
**Insight:** When a wrapper escapes for a shell that parses twice (cmd.exe + batch %*), check whether the escaping is conditioned on a narrow path (here node_modules/.bin); any other batch file forwarding args re-parses the string. Also test trailing dots/spaces to bypass extension-based detection, mirroring CVE-2024-36138.

## Proof of concept (copied exactly from the original report)

**cross-spawn spawn.sync npm argument injection PoC**

```
const spawn = require('cross-spawn');

// Runs calc.exe on Windows
spawn.sync('npm', ['" & calc & "']);
```

