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
exec(`convert ${file} out.png`);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.
- AI code audit taxonomy
- Ruff rules
- skill: code-review
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"
}
}
}