Why it matters
A YAML document can name Python objects to construct, so loading an untrusted document runs code.
How to fix it
Use yaml.safe_load, or pass Loader=yaml.SafeLoader.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
import yaml
def read_config(text):
return yaml.load(text)import yaml
def read_config(text):
first = yaml.safe_load(text)
second = yaml.load(text, Loader=yaml.SafeLoader)
return first, secondWhat 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
- Open redirect from request input (Python)
PythonSeverity: Medium
trustivan-python-taint-open-redirect - Subprocess shell true (Python)
PythonSeverity: Medium
trustivan-python-subprocess-shell-true - Code injection from request input (Python)
PythonSeverity: High
trustivan-python-taint-code-injection - Weak hash (Python)
PythonSeverity: Medium
trustivan-python-weak-hash - Template injection from request input (Python)
PythonSeverity: High
trustivan-python-taint-template-injection - TLS verification disabled (Python)
PythonSeverity: High
trustivan-python-tls-verification-disabled
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