Why it matters
Data encrypted this way can be read or patterned by an attacker who captures enough of it, so the encryption no longer keeps it confidential.
How to fix it
Use AES in GCM mode, or ChaCha20-Poly1305.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
from Crypto.Cipher import AES
def seal(key, block):
cipher = AES.new(key, AES.MODE_ECB)
return cipher.encrypt(block)from Crypto.Cipher import AES
def seal(key, nonce, block):
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
return cipher.encrypt_and_digest(block)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
- Django CSRF exempt (Python)
PythonSeverity: Medium
trustivan-python-django-csrf-exempt - SSH host key not verified (Python)
PythonSeverity: High
trustivan-python-ssh-host-key-not-verified - Tarfile extractall (Python)
PythonSeverity: Medium
trustivan-python-tarfile-extractall - Bind all interfaces debug server (Python)
PythonSeverity: Medium
trustivan-python-bind-all-interfaces-debug-server - XML external entities (Python)
PythonSeverity: Medium
trustivan-python-xml-external-entities - Eval non literal (Python)
PythonSeverity: Medium
trustivan-python-eval-non-literal
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