cross-spawn: Command injection on Windows when spawning batch files
Published 1 Dec 2026 · Updated 1 Dec 2026
Affected packages
- Affected
- >=7.0.0 <7.1.0
- Fixed in
- 7.1.0
npm install cross-spawn@7.1.0- Affected
- <6.0.7
- Fixed in
- 6.0.7
npm install cross-spawn@6.0.7Which cross-spawn does your project really install?
Works for private projects: the file is read in memory to run the scan and then dropped. Also reads yarn.lock, pnpm-lock.yaml or package.json.
Public repo?
Look after several JavaScript apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Details
Impact
On Windows, cross-spawn runs commands that aren't executables (.exe or .com), such as batch files (.bat or .cmd), through cmd.exe, and escapes the command and its arguments for it.
A batch file that forwards its arguments, e.g. with %*, makes cmd.exe parse them a second time. cross-spawn only accounted for that second parse when the batch file was an npm cmd-shim located in node_modules/.bin. For any other batch file, such as npm.cmd, globally installed package shims or user batch files, a crafted argument could break out of its quotes and run arbitrary commands:
const spawn = require('cross-spawn');
// Runs calc.exe on Windows
spawn.sync('npm', ['" & calc & "']);The following were also affected:
- Batch file detection could be bypassed with trailing dots or spaces in the command name (e.g.
tool.bat), which Windows strips, similar to Node.js' CVE-2024-36138. %VAR%in an argument was expanded if an environment variable namedVAR^existed.!VAR!in an argument was expanded if delayed expansion was enabled in the registry.
Applications are affected if they pass untrusted input as arguments to a command that runs through cmd.exe on Windows. Other platforms aren't affected, and neither is options.shell, which doesn't escape the command or its arguments by design.
Patches
This is fixed in 7.1.0 and 6.0.7. Batch file arguments are now escaped with double quotes, like Rust does since the BatBadBut vulnerability (CVE-2024-24576), % is neutralized, cmd.exe runs with /e:on /v:off, batch files are detected after stripping trailing dots and spaces, and line breaks, which cmd.exe can't escape, are rejected with a TypeError.
Some limitations can't be fixed by any escaping, such as batch files that use %~1 unquoted. Please see the "Windows argument escaping" section of the README.
Workarounds
Validate untrusted input so that only a safe subset is allowed, and call executables directly rather than through batch files.
Credits
Thanks to Duong Bui Thai (LinkedIn) for privately reporting the quote breakout through batch files outside node_modules/.bin and the !VAR! expansion under delayed expansion, and to @mohd-akram for publicly reporting the batch file injection in #171.
Is GHSA-ghv9-86vm-4v8m in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected cross-spawn, and gives you the command that fixes it.
More advisories for cross-spawn
- HighCVE-2024-21538Regular Expression Denial of Service (ReDoS) in cross-spawn · 8 Nov 2024
References
- Linkgithub.com/moxystudio/node-cross-spawn/security/advisories/GHSA-ghv9-86vm-4v8m
- Advisorynvd.nist.gov/vuln/detail/CVE-2026-137199
- Linkgithub.com/moxystudio/node-cross-spawn/issues/171
- Linkgithub.com/moxystudio/node-cross-spawn/pull/191
- Linkgithub.com/moxystudio/node-cross-spawn/pull/192
- Linkgithub.com/moxystudio/node-cross-spawn/commit/1b71aa519a2e4f97d1f3ee27f0e2fc24ba17cf1a
- Linkgithub.com/moxystudio/node-cross-spawn/commit/244ffeaa8473de0080c93ebbf779bb953b94114b
- Packagegithub.com/moxystudio/node-cross-spawn
- Linkgithub.com/moxystudio/node-cross-spawn/releases/tag/v6.0.7
- Linkgithub.com/moxystudio/node-cross-spawn/releases/tag/v7.1.0
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.