subprocess gets a command line as one string without shell=True
What it finds
subprocess.run("git status"): without shell=True, a string is the name of the program to run, spaces included, so this looks for a program called git status and fails with FileNotFoundError on POSIX systems. A list, ["git", "status"], passes the words as arguments.
Reported are string literals with a space given as the command to the functions of subprocess that run a program, when shell is not given or is False.
From the rule's source, command_string_without_shell.rs.
import subprocess def run(name): subprocess.run("git status")tx0 reports: subprocess.run takes this whole string as the name of the program to run subprocess.check_output("ls -l", shell=False)tx0 reports: subprocess.check_output takes this whole string subprocess.run("git status", shell=True) subprocess.run(["git", "status"]) subprocess.run("ls") subprocess.run(name) Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:command-string-without-shell" = "off"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:command-string-without-shell] reason="..."tx0 explain tx0/python:command-string-without-shell shows the same in the terminal. Found a false positive? Report it.