Data is encrypted with an initialization vector or nonce written in the source

tx0/python:constant-ivrecommendedwarningsecurity, cwe-329

What it finds

Modes such as CBC, CTR and GCM need a fresh, unpredictable IV or nonce for every message. With a fixed one, equal messages encrypt to equal ciphertexts, and in CTR and GCM two messages under the same key and nonce reveal each other. Reported are string and bytes literals given as iv or nonce to AES.new and the other ciphers of PyCryptodome, and as the argument of the modes of cryptography, such as modes.CBC(b"...").

From the rule's source, constant_iv.rs.

Example from the rule's tests
from Crypto.Cipher import AESfrom cryptography.hazmat.primitives.ciphers import modes a = AES.new(key, AES.MODE_CBC, iv=b"0123456789abcdef")tx0 reports: this IV or nonce is written in the sourceb = modes.CBC(b"0123456789abcdef")tx0 reports: this IV or nonce is written in the sourcec = modes.CBC(os.urandom(16))d = AES.new(key, AES.MODE_GCM, nonce=nonce)
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:constant-iv" = "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:constant-iv] reason="..."

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