eval or exec runs code that is not a literal
What it finds
eval(text), exec(code): the builtins run a string as Python code with all the rights of the program. When any part of the string comes from outside, whoever controls it can run what they like (CWE-95). ast.literal_eval reads literals safely, and a dict of functions covers most uses of names chosen at run time.
Calls whose code is a string literal are left alone, since their code is fixed when the program is written. Only the builtins are reported, not methods or functions of the same name.
From the rule's source, eval_exec.rs.
import builtins def run(expression, code, eval_): value = eval(expression)tx0 reports: eval runs code built at run time exec(code, {})tx0 reports: exec runs code built at run time exec("x = 1") eval("1 + 2") return value, eval_(expression), builtins class Shell: def eval(self, text): return self.eval(text) 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/python:eval-exec" = "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:eval-exec] reason="..."tx0 explain tx0/python:eval-exec shows the same in the terminal. Found a false positive? Report it.