A broken cipher or the ECB mode encrypts data

tx0/python:weak-cipherrecommendedwarningsecurity, cwe-327

What it finds

DES.new(key, DES.MODE_CBC), algorithms.ARC4(key), AES.MODE_ECB: DES, triple DES, RC2, RC4, Blowfish and IDEA have keys or blocks small enough to be broken, and ECB mode encrypts equal blocks to equal output, which shows the shape of the data (CWE-327). AES in GCM mode, or ChaCha20-Poly1305, encrypt and authenticate.

Reported are the new functions of those ciphers in PyCryptodome and PyCrypto, the cipher classes of cryptography, and mentions of ECB mode in both.

From the rule's source, weak_cipher.rs.

Example from the rule's tests
from Crypto.Cipher import AES, DESfrom cryptography.hazmat.primitives.ciphers import algorithms, modes  def encrypt(key, iv):    a = DES.new(key, DES.MODE_CBC, iv)tx0 reports: the cipher DES can be broken    b = AES.new(key, AES.MODE_ECB)tx0 reports: ECB mode encrypts equal blocks to equal output    c = algorithms.ARC4(key)tx0 reports: the cipher ARC4 can be broken    d = modes.ECB()tx0 reports: ECB mode encrypts    e = AES.new(key, AES.MODE_GCM)    f = algorithms.AES(key)    return a, b, c, d, e, f
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:weak-cipher" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:weak-cipher] reason="..."

tx0 explain tx0/python:weak-cipher shows the same in the terminal. Found a false positive? Report it.