A command built at run time is run through the shell

tx0/python:subprocess-shellrecommendedwarningsecurity, cwe-78

What it finds

subprocess.run(command, shell=True): the command goes to the system shell, which reads quotes, ;, |, $(...) and more in it. When part of the command comes from outside, it can run other commands (CWE-78). A list of arguments without a shell passes each value as it is.

Reported are the functions of subprocess with shell=True, and getoutput and getstatusoutput, which always use the shell, when the command is not a string literal.

From the rule's source, subprocess_shell.rs.

Example from the rule's tests
import subprocessfrom subprocess import Popen  def run(name, flag):    subprocess.run("ls " + name, shell=True)tx0 reports: subprocess.run runs a command built at run time through the shell    Popen(f"grep {name}", shell=True)tx0 reports: subprocess.Popen runs    subprocess.getoutput(name)tx0 reports: subprocess.getoutput runs    subprocess.run("ls -l", shell=True)    subprocess.run(["ls", name])    subprocess.run(name, shell=flag)    subprocess.call(name, shell=False)
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/python:subprocess-shell" = "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/python:subprocess-shell] reason="..."

tx0 explain tx0/python:subprocess-shell shows the same in the terminal. Found a false positive? Report it.