Skip to main content
CriticalCodeOWASP A03:2021CWE-78

How to fix: child_process.spawn with shell:true

spawn(cmd, { shell: true }) or spawn("sh -c " + cmd) re-routes the command through /bin/sh, so any unescaped metacharacter in arguments (& ; | $ ` \n) executes attacker commands.

Why it matters

Attacker-controlled arguments gain full shell-injection capability, leading to RCE on the host.

The `code-cmdi-spawn-shell-true` check verifies that the server does not expose the `cmdi-spawn-shell-true` weakness in the code category. The detection runs against the response headers, body, or auxiliary probes (DNS, TLS, async fetch) as appropriate.

How to fix it

  1. 1Pass args as a separate array; spawn with shell:false and let Node escape them.
  2. 2Validate every argument against a strict allowlist before invoking.
  3. 3Run the child process under a non-root user and inside a sandboxed environment.

Code examples

Set shell: false in spawn options

TypeScript
import { spawn } from "child_process";

// BAD: shell: true, user input can inject shell commands
spawn("convert", [userInput], { shell: true });

// GOOD: shell: false (default) with argument array
spawn("convert", ["-resize", "100x100", validatedInputPath, outputPath], {
  shell: false, // no shell expansion
  timeout: 10_000,
});

References

Detected automatically by VulnRadar. The check id is code-cmdi-spawn-shell-true, stable across every scan so you can filter or diff on it.

See every code check

Questions

How severe is child_process.spawn with shell:true?
VulnRadar rates this critical severity in the code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id code-cmdi-spawn-shell-true, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does child_process.spawn with shell:true map to?
It maps to CWE-78. In the OWASP Top 10 it falls under A03:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for child_process.spawn with shell:true

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: child_process.spawn with shell:true | VulnRadar