Why it matters
The caller can run any code with this process's privileges.
How to fix it
Do not evaluate request data. Parse literals with ast.literal_eval, or map the value to a known operation with a dictionary lookup.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
from flask import Flask, request
app = Flask(__name__)
@app.route("/calc")
def calc():
expression = request.args.get("expr")
return str(eval(expression))import ast
from flask import Flask, request
app = Flask(__name__)
@app.route("/calc")
def calc():
expression = request.args.get("expr")
return str(ast.literal_eval(expression))What TrustIvan reads
Runs on repository scans of Python source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- Template injection from request input (Python)
PythonSeverity: High
trustivan-python-taint-template-injection - Open redirect from request input (Python)
PythonSeverity: Medium
trustivan-python-taint-open-redirect - Deserialization from request input (Python)
PythonSeverity: High
trustivan-python-taint-deserialization - YAML unsafe load (Python)
PythonSeverity: High
trustivan-python-yaml-unsafe-load - XSS from request input (Python)
PythonSeverity: High
trustivan-python-taint-xss - Subprocess shell true (Python)
PythonSeverity: Medium
trustivan-python-subprocess-shell-true
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation