Why it matters
Any part of it that comes from outside the program is parsed for shell metacharacters.
How to fix it
Pass the command as a list and drop shell=True, so each value is delivered as one argument.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
import subprocess
def archive(directory):
subprocess.run("tar czf backup.tgz " + directory, shell=True, check=True)import subprocess
def archive(directory):
subprocess.run(["tar", "czf", "backup.tgz", directory], check=True)
subprocess.run("date", shell=True, check=True)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
- YAML unsafe load (Python)
PythonSeverity: High
trustivan-python-yaml-unsafe-load - Weak hash (Python)
PythonSeverity: Medium
trustivan-python-weak-hash - Open redirect from request input (Python)
PythonSeverity: Medium
trustivan-python-taint-open-redirect - TLS verification disabled (Python)
PythonSeverity: High
trustivan-python-tls-verification-disabled - Code injection from request input (Python)
PythonSeverity: High
trustivan-python-taint-code-injection - SSL unverified context (Python)
PythonSeverity: High
trustivan-python-ssl-unverified-context
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