A command line built from values is run through a shell by child_process
What it finds
exec("git log " + branch), execSync(convert ${file} out.png): exec and execSync of child_process hand the whole string to a shell. A value spliced into it that contains ;, |, $(...) or quotes runs commands of its own. execFile and spawn with an array of arguments run the program without a shell.
Reported are calls of exec or execSync imported from child_process or node:child_process, by name or through the module object, whose command is built with + or a template with substitutions, and calls of spawn, spawnSync, execFile or execFileSync with shell: true and a built command.
From the rule's source, shell_command_string.rs.
import { exec, execFile } from "child_process";import * as cp from "node:child_process";function run(branch: string) { exec("git log " + branch);tx0 reports: exec runs this command line, built from values, through a shell cp.execSync(`git checkout ${branch}`);tx0 reports: execSync runs this command line cp.spawn(`ls ${branch}`, { shell: true });tx0 reports: spawn runs this command line execFile("git", ["log", branch]); exec("git status");} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:shell-command-string" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:shell-command-string] reason="..."tx0 explain tx0/ts:shell-command-string shows the same in the terminal. Found a false positive? Report it.