Static analysis (SAST) check · Python

Weak cipher (Python)

DES, Triple DES, RC4 and Blowfish are no longer safe, and ECB mode reveals which plaintext blocks repeat.

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.

Vulnerable: reported (Python)
from Crypto.Cipher import AES


def seal(key, block):
    cipher = AES.new(key, AES.MODE_ECB)
    return cipher.encrypt(block)
Fixed: not reported (Python)
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

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

See TrustIvan on your own estate.

Book thirty minutes with an engineer and bring an image, a repository or a cloud account, or start free on the hosted service.