79% vs 51%: independent neobanks lag on app security. Read the report

Deep Dive

Deep Dive

cross-spawn Windows Batch Command Injection (CVE-2026-137199)

On Windows, cross-spawn passes crafted arguments to batch files through cmd.exe, allowing command injection; fixed in 6.0.7 and 7.1.0.

TL;DR

  • On Windows, cross-spawn escaped arguments once before cmd.exe parsed them. A batch file that forwards its arguments makes cmd.exe parse them a second time, so a crafted argument could run a command. The maintainers disclosed the flaw on 2026-11-28.
  • Applications that pass untrusted input as arguments to a command routed through cmd.exe are exposed. That covers npm cmd-shims, globally installed package shims and user batch files. Other platforms are not affected.
  • The maintainers rate it High; NVD records CVSS v4.0 9.2 Critical. No exploitation in the wild is known, and it is not in CISA KEV as of 2026-12-01.
  • Upgrade to 6.0.7 or 7.1.0. See "How do I fix it?" for the input-validation workaround.

Am I affected?

You are exposed when a Windows application passes untrusted input as an argument to a command that cross-spawn routes through cmd.exe. All of these conditions must hold:

  • The process runs on Windows. The flaw is in the cmd.exe quoting path, so Linux and macOS are not affected.
  • The application calls cross-spawn or cross-spawn.sync, either directly or through a dependency.
  • The spawned command is not a native executable (.exe or .com). Batch files (.bat or .cmd), npm cmd-shims such as npm.cmd, and global package shims go through cmd.exe.
  • The application passes attacker-influenced data in the argument list. A fixed command with fixed arguments is not exploitable.
  • The application does not use options.shell. That mode does not escape arguments by design and is documented as unsafe.

cross-spawn is widely used. npm counted 343,285,877 downloads of the cross-spawn package in the week of 2026-11-23 to 2026-11-29 (npm). Many command-line tools and build scripts pull it in transitively, so the vulnerable version can sit deep in a dependency tree.

Branch Affected versions Fixed version
cross-spawn 6 6.0.0 to 6.0.6, and every release before 6.0.0 6.0.7
cross-spawn 7 7.0.0 to 7.0.6 7.1.0

Check the version in the project and in the lockfile:

npm ls cross-spawn
grep -A2 '"node_modules/cross-spawn"' package-lock.json

With pnpm or Yarn, ask the package manager which dependencies pulled it in:

pnpm why cross-spawn
yarn why cross-spawn

Then look for the code path. Search the application for cross-spawn imports and for spawn or spawnSync calls that pass user input:

grep -Rn "require('cross-spawn')\|from 'cross-spawn'" src

A dependency that runs a batch file with untrusted arguments is exposed even when your own code is clean.

How do I fix it?

Upgrade to 6.0.7 on the 6 line or 7.1.0 on the 7 line, and make every transitive copy resolve to the fixed release. The advisory lists both versions as patched.

  1. Upgrade a direct dependency:
npm install cross-spawn@7.1.0

Use cross-spawn@6.0.7 when the project must stay on the 6 line. Do not assume a major upgrade is safe for the calling code; read the 7.x changelog first.

  1. Force transitive copies to the fixed release with an override, then reinstall:
npm pkg set overrides.cross-spawn=7.1.0
rm -rf node_modules package-lock.json
npm install

With pnpm, use pnpm.overrides in package.json; with Yarn, use resolutions.

  1. Confirm that only fixed versions remain:
npm ls cross-spawn

If you cannot upgrade yet, validate untrusted input before it reaches the argument list. Allow only a safe subset, such as letters, digits and a fixed set of characters, and reject the rest. Call native executables directly instead of batch files wherever the tool allows it.

The maintainers' advisory states that some batch files cannot be made safe by any escaping, such as a batch file that reads %~1 without quotes. Input validation and direct executables are the only reliable fallback for those cases.

What is the root cause?

cross-spawn escaped arguments with carets (^) for cmd.exe but assumed cmd.exe parses each command once. A batch file that forwards its arguments with %* or reads them with "%~1" makes cmd.exe parse them again, and the caret escapes are gone by then.

cross-spawn runs a command through cmd.exe when the target is not a native executable. That includes batch files. The library has an escape helper that quotes each argument and adds carets before shell metacharacters. The helper had a special case for npm cmd-shims under node_modules/.bin, because those shims forward their arguments and cause a second parse.

This is lib/parse.js at the last affected 6.x release:

const isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
...
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
...
parsed.command = escape.command(parsed.command);
parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
...
parsed.args = ['/d', '/s', '/c', `"${shellCommand}"`];

needsDoubleEscapeMetaChars was true only for a .cmd file inside a node_modules/.bin directory. Any other batch file got single escaping. Its %* forwarded the arguments to a second cmd.exe parse, where a ^ no longer protected a metacharacter.

lib/util/escape.js shows the single escape and the optional second one:

const metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;

function escapeArgument(arg, doubleEscapeMetaChars) {
  ...
  arg = arg.replace(metaCharsRegExp, '^$1');

  if (doubleEscapeMetaChars) {
    arg = arg.replace(metaCharsRegExp, '^$1');
  }

  return arg;
}

Three related gaps made the problem broader than the double parse.

First, batch detection looked only for .cmd under node_modules/.bin. Windows strips trailing dots and spaces from file names, so a command such as tool.bat still runs tool.bat but failed the check.

Second, %VAR% was escaped with ^%, which does not stop expansion when an environment variable named VAR^ exists. The expanded value then reaches the second parse.

Third, !VAR! is expanded when delayed expansion is enabled in the registry, even when the library did not ask for it.

How is it exploited?

An attacker who controls an argument makes cmd.exe read it as a command on the second parse, then runs an arbitrary program as the user that started the application. The advisory gives a one-line example.

  1. The application builds an argument list from untrusted input and calls cross-spawn with a batch-file command, such as npm.
  2. cross-spawn resolves the command to a .cmd file and escapes the arguments once with carets.
  3. cmd.exe starts the batch file. The batch file forwards the arguments with %* or reads them with "%~1", so cmd.exe parses them a second time.
  4. On the second parse the caret escapes are gone. A quote in the argument closes the quoted string, and the following & starts a new command.
  5. The new command runs with the privileges of the process that called cross-spawn.

The advisory's example sends " & calc & " as an argument to npm:

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

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

The public proof of concept is this short example, not a full exploit chain. No exploitation in the wild has been reported, and the issue is not in CISA KEV as of 2026-12-01.

The advisory credits Duong Bui Thai for the private report and @mohd-akram for the public issue.

How does the attack flow?

An untrusted argument reaches cross-spawn, a batch file forwards it to a second cmd.exe parse, and the injected command runs as the calling process.

flowchart LR A["Untrusted argument from the application"] --> B["cross-spawn quotes it once with carets"] B --> C["cmd.exe starts a batch file"] C --> D["Batch file forwards the argument with %* or %~1"] D --> E["Second cmd.exe parse, caret escapes gone"] E --> F["Quote breakout starts a new command"] F --> G["Command runs as the calling process"]

What can an attacker do?

An attacker who controls an argument to a batch-file command can run arbitrary commands on the Windows host. The command runs as the user that started the application, which is often a developer or a CI runner.

On a developer workstation the command can read the developer's files and credentials. On a CI runner it can reach the repository token, the registry token and the deployment secrets that the job exposes. The advisory demonstrates calc.exe, a harmless marker; a real payload would be chosen by the attacker.

The impact depends on the process. An application that only formats a fixed command with fixed arguments gives the attacker nothing. An application that passes a filename, a branch name, a package name or a URL into the argument list of a batch-file command can hand over command execution.

Windows is required. The advisory states that other platforms and the options.shell mode are not affected, and options.shell is unsafe by design.

Why does the fix work?

The fix detects batch files after stripping trailing dots and spaces, then escapes their arguments with double quotes instead of carets. It also neutralises %, disables delayed expansion and rejects line breaks.

This is the diff in lib/parse.js:

-const isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
+const isBatchFileRegExp = /\.(?:bat|cmd)$/i;
+const trailingDotsAndSpacesRegExp = /[. ]+$/;
...
-        const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
...
-        parsed.command = escape.command(parsed.command);
-        parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
+        if (isBatchFile(parsed, commandFile)) {
+            parsed.command = escape.batchCommand(parsed.command);
+            parsed.args = parsed.args.map((arg) => escape.batchArgument(arg));
+        } else {
+            parsed.command = escape.command(parsed.command);
+            parsed.args = parsed.args.map((arg) => escape.argument(arg));
+        }
...
-        parsed.args = ['/d', '/s', '/c', `"${shellCommand}"`];
+        parsed.args = ['/d', '/e:on', '/v:off', '/s', '/c', `"${shellCommand}"`];

Batch detection now applies to every .bat and .cmd, after trailingDotsAndSpacesRegExp removes a trailing dot or space. The new escapeBatchArgument quotes the whole argument and doubles embedded quotes, which keeps the quoting balanced through both parses. The fix follows the approach Rust adopted after the BatBadBut vulnerability.

lib/util/escape.js also replaces % with %%cd:~,%, an empty substring of the cd variable that interrupts %VAR% expansion. The command line adds /e:on to enable command extensions, which the replacement relies on, and /v:off to disable delayed expansion even when the registry enables it. Line breaks, which cmd.exe cannot escape, now throw a TypeError.

The patch closes the quote breakout through batch files and the three bypasses. It does not change options.shell, which remains unsafe by design, and it cannot make a batch file that reads %~1 without quotes safe.

How do I check if I was compromised?

Look for child processes that a build tool or application started through cmd.exe and that do not match its configured command. Windows process auditing is the primary source.

Enable command-line process auditing if it is not already on, then query the events:

auditpol /set /subcategory:"Process Creation" /success:enable
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4688} |
  Where-Object { $_.Message -match 'cmd.exe' } |
  Select-Object TimeCreated, Message -First 50

Review the process command lines for a second command after &, | or &&. A build tool that normally runs npm.cmd install and instead starts calc.exe is a strong lead.

Check the npm and package-manager logs for argument strings that contain quotes and shell metacharacters. The advisory's example contains " & calc & ", but an attacker can choose any command:

grep -REn '(&|&&|\|).*(calc|powershell|cmd|curl|bitsadmin)' ~/.npm/_logs 2>/dev/null

No vendor indicator set has been published. A failed attempt may leave no trace, and a successful short command may leave only the cmd.exe process record.

Timeline

  • 2025-02-21: A public issue reports batch-file command injection in cross-spawn.
  • 2026-11-28: The maintainers publish advisory GHSA-ghv9-86vm-4v8m and release 6.0.7 and 7.1.0.
  • 2026-11-30: NVD publishes CVE-2026-137199.

From the public report to the fix and the NVD record
Figure 1: A public report on 2025-02-21, the advisory and fixed releases on 2026-11-28, and the NVD record on 2026-11-30. Source: cross-spawn issue #171, GHSA-ghv9-86vm-4v8m and NVD, checked December 1, 2026

FAQ

Does this affect Linux or macOS?

No. The flaw is in the cmd.exe quoting path, which cross-spawn uses only on Windows. The advisory states that other platforms are not affected.

Is a project that never calls cross-spawn directly affected?

Yes, when a dependency calls it with untrusted arguments. Many command-line tools and build scripts use cross-spawn transitively, so check the lockfile rather than only your own imports.

Is options.shell affected?

No, but options.shell is unsafe by design because it does not escape the command or its arguments. The advisory excludes it from the affected surface, and the fix does not change it.

Which version should I upgrade to?

Upgrade to 6.0.7 on the 6 line or 7.1.0 on the 7 line. If a transitive dependency pins an older copy, add an override so every copy resolves to the fixed release.

Is there a public proof of concept?

Yes. The advisory includes a one-line call that runs calc.exe on Windows. No exploitation in the wild has been reported.

Does input validation fully replace the patch?

No. Validation reduces the risk but the only complete fix is the patched release. The advisory notes that some batch files cannot be escaped safely, so validate input and call native executables directly where possible.

Find exposed build hosts with Ostorlab

Ostorlab's software composition analysis inventories the open-source packages in your repositories and flags the versions an advisory marks as affected. Use it to find every transitive copy of cross-spawn that still resolves below the fixed release before a build host runs attacker-controlled input.

References

  • cross-spawn, advisory GHSA-ghv9-86vm-4v8m, "Command injection on Windows when spawning batch files", published 2026-11-28 (checked December 1, 2026): https://github.com/moxystudio/node-cross-spawn/security/advisories/GHSA-ghv9-86vm-4v8m
  • NVD, CVE-2026-137199 record (checked December 1, 2026): https://nvd.nist.gov/vuln/detail/CVE-2026-137199
  • cross-spawn, fix commit 244ffeaa8473de0080c93ebbf779bb953b94114b (checked December 1, 2026): https://github.com/moxystudio/node-cross-spawn/commit/244ffeaa8473de0080c93ebbf779bb953b94114b
  • cross-spawn, pull request 191, fix for the 7 line (checked December 1, 2026): https://github.com/moxystudio/node-cross-spawn/pull/191
  • cross-spawn, public issue 171 (checked December 1, 2026): https://github.com/moxystudio/node-cross-spawn/issues/171
  • cross-spawn, release v6.0.7, published 2026-11-28 (checked December 1, 2026): https://github.com/moxystudio/node-cross-spawn/releases/tag/v6.0.7
  • cross-spawn, release v7.1.0, published 2026-11-28 (checked December 1, 2026): https://github.com/moxystudio/node-cross-spawn/releases/tag/v7.1.0
  • npm, cross-spawn package page, 343,285,877 downloads in the week of 2026-11-23 to 2026-11-29 (checked December 1, 2026): https://www.npmjs.com/package/cross-spawn
  • CISA, Known Exploited Vulnerabilities Catalog, catalog version 2026.11.30 (checked December 1, 2026): https://www.cisa.gov/known-exploited-vulnerabilities-catalog

Free scan

Scan your own app for free

or book a demo

Keep reading

Related articles

Browse the blog