redline
HighSecurityshell-injection

Shell command from strings

Shell command from strings. Runs a shell command assembled from strings (exec(`rm ${).

This is how the comment reads inline, under the flagged line.

Why it matters

A filename with ; or $() in it becomes a second command. Shell parsing is the bug.

What to do

Pass an argument list without a shell: execFile(cmd, args), subprocess.run([cmd, *args]).

Examples

Flagged
exec(`convert ${file} out.png`);
Better
execFile("convert", [file, "out.png"]);

What it catches

It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript, Python. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.

Flagged

exec(`rm ${p}`);
src/app.py
subprocess.run(cmd, shell=True)

Left alone

execFile("rm", [p]);

Research

Shell commands built from strings (`shell=True`, `os.system`, `exec` with a template). A crafted input runs an extra command.

Turn it off or change it

In a config file for the CLI, or in the API's rules field:

{
  "rules": {
    "disable": [
      "shell-injection"
    ],
    "severity": {
      "shell-injection": "low"
    }
  }
}

Read the source or report a false positive.