Skip to content

Command Injection via Child Process

Description

Detected potentially unsafe user input passed to child_process methods (exec, spawn). This may lead to command injection if the data isn't properly sanitized. Avoid using dynamic values in command strings, especially if derived from user input.

Examples

Insecure Code

javascript
const { exec } = require('child_process'); exec(userInput);

Secure Code

javascript
const { exec } = require('child_process'); exec('ls -l');

Remediation

Use hardcoded command paths, never pass raw strings or filenames directly from input, and prefer libraries that provide native functionality over shell commands

Rule Details

FieldValue
IDCODE-0769
CategoryInjection
SeverityHIGH
CWECWE-78
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagscommand injection, child process
OWASPA03:2021-Injection