Why it matters
Another process can create it first and control what this program reads or writes.
How to fix it
Use tempfile.mkstemp or tempfile.NamedTemporaryFile.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
import tempfile
def scratch():
path = tempfile.mktemp()
with open(path, "w") as handle:
handle.write("x")import os
import tempfile
def scratch():
descriptor, path = tempfile.mkstemp()
with os.fdopen(descriptor, "w") as handle:
handle.write("x")
return pathWhat 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
- Insecure random secret (Python)
PythonSeverity: Medium
trustivan-python-insecure-random-secret - XML external entities (Python)
PythonSeverity: Medium
trustivan-python-xml-external-entities - JWT verification disabled (Python)
PythonSeverity: High
trustivan-python-jwt-verification-disabled - Tarfile extractall (Python)
PythonSeverity: Medium
trustivan-python-tarfile-extractall - Flask debug enabled (Python)
PythonSeverity: High
trustivan-python-flask-debug-enabled - Django CSRF exempt (Python)
PythonSeverity: Medium
trustivan-python-django-csrf-exempt
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