OS commands are security-sensitive. For example, their use has led in the past to the following vulnerabilities:

Applications that execute operating system commands or execute commands that interact with the underlying system should neutralize any externally-provided input used to construct those commands. Failure to do so could allow an attacker to execute unexpected or dangerous commands, potentially leading to loss of confidentiality, integrity or availability.

This rule flags code that specifies the name of the command to run. The goal is to guide security code reviews.

Ask Yourself Whether

(*) You are at risk if you answered yes to any of those questions.

Recommended Secure Coding Practices

Restrict the control given to the user over the executed command:

Restrict which users can have access to the command:

Reduce the damage the command can do:

Questionable Code Example

const cp = require('child_process');

// The following method calls are questionable. Validate the parameter string.
cp.exec(str);
cp.execSync(str);

// The following method calls are questionable if the shell parameter is set to true.
cp.spawn(str, { shell: true });
cp.spawnSync(str, { shell: true });
cp.execFile(str, { shell: true });
cp.execFileSync(str, { shell: true });

Exceptions

No issue will be raised if the string being passed is fully hard-coded.

See