CVE-2024-27980: Node.js Command Injection in child_process on Windows (BatBadBut)

High Severity CWE-78: Command Injection Node.js 14, 16, 18 (EOL) Windows Platform

A command injection vulnerability in Node.js on Windows when spawning batch files (.bat or .cmd). Upstream fixes shipped for Node.js 20.x (and late 18.x), so only older or unupgraded EOL Node.js deployments need backport help.

Provided as is, test before deploying All guidance and architectural workarounds on this page are provided as is, without warranty. Test every change in a staging environment before deploying to production. Unverified DIY wrapper code has been withheld because incomplete metacharacter checks on Windows can be bypassed.

1. Affected Environments & Upstream Patch Scope

2. Technical Root Cause

On Windows, batch files are not native PE binaries. When an application passes a .bat or .cmd path to the Windows CreateProcessW API, the operating system transparently invokes cmd.exe /c to parse and run the script.

Developers frequently rely on child_process.spawn(command, [args]) assuming that passing arguments as an array avoids shell injection. Because the target is a batch script, cmd.exe parses the concatenated command line after process creation. Metacharacters such as &, |, <, >, ^, and % are interpreted by cmd.exe as command delimiters or variable expansions rather than literal argument text.

As a result, passing untrusted values into the argument list of a batch script lets an attacker break out of the argument context and execute arbitrary commands with the privileges of the Node.js process.

3. Upstream Fix Behavior vs Legacy Impact

The upstream Node.js security release fixed this by introducing an explicit behavioral check on Windows: spawning a .bat or .cmd file without setting { shell: true } now fails with an EINVAL error (and follow-up patches addressed edge cases tracked under CVE-2024-36138).

For legacy applications pinned to Node.js 14 or 16 (or older 18.x builds blocked by native C++ addon incompatibilities), no official patch exists for 14/16 and upgrading straight to Node 20+ can require extensive dependency rewrites. Note also that passing { shell: true } without strict, complete input sanitization still leaves batch invocations exposed.

4. Remediation & Architecture Hardening

Where upgrading to patched Node.js 20.15.1+ (or 22 LTS+) is not immediately possible, prefer eliminating batch wrappers rather than relying on ad-hoc regex filters:

Running Legacy Node.js Services in Production?

Legacy Node.js applications (v14, v16, and frozen v18) running on Windows and Linux face unpatched core vulnerabilities and native addon incompatibilities. CrawlShield delivers tested runtime security patches and compliance documentation tailored for older EOL Node.js environments.

Request legacy Node.js coverage