How to fix: child_process.spawn/execFile concatenated args
spawn("git " + userArg) or execFile(`tool ${userArg}`) builds an argument string via concatenation. Although execFile itself does not invoke a shell, the embedded space allows attackers to inject additional flags or arguments.
Why it matters
Argument injection lets attackers invoke unintended subcommands, read arbitrary files, or trigger built-in shell escapes.
The `code-cmdi-process-spawn` check verifies that the server does not expose the `cmdi-process-spawn` 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
- 1Pass user input as a discrete array element: spawn(cmd, [userArg]).
- 2Allowlist each argument value before passing to execFile.
- 3Use -- separator to stop flag parsing when relevant.
Code examples
Validate arguments before process.spawn
import { spawn } from "child_process";
// Allowlist: only known-safe filenames
const ALLOWED_EXT = /^[a-zA-Z0-9_-]+\.(png|jpg|webp)$/;
if (!ALLOWED_EXT.test(filename)) throw new Error("Invalid filename");
spawn("convert", [filename, "output.png"], { shell: false });References
Detected automatically by VulnRadar. The check id is code-cmdi-process-spawn, stable across every scan so you can filter or diff on it.
More code checks
- CriticalForm Submits Data Over Insecure HTTP
- MediumPotential Prototype Pollution Sinks Detected
- HighPotential Command Injection Vectors
- HighJWT Decoded Without Signature Verification
- HighPotential Path Traversal Vulnerability
- HighInsecure Authentication Mechanisms Detected
- HighPotential Insecure Deserialization
- Mediumeval() Usage in Inline Scripts
Questions
- How severe is child_process.spawn/execFile concatenated args?
- VulnRadar rates this high 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-process-spawn, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does child_process.spawn/execFile concatenated args 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.