fixed-iv
An encryption IV written into the code.
- Group
- Code
- Runs
- Runs under ur scan:
ur scan --rule fixed-iv - Level
- warning
- Reads
- Every file
- Fix
- None: the safe form depends on what the value is meant to be
Why
An initialization vector is a literal, so every value encrypted with the same key starts the same way, and equal plaintexts give equal ciphertexts. Make a new random IV for each encryption, as cipher.random_iv does, and store it with the ciphertext.
The fix, as Ur suggests it: make a random IV for each encryption.
For agents
Never use a fixed IV; make a random one for each encryption.
Example
config/initializers/constants.rbCIPHER_IV = "PPKLKAJDKGHALDJL4828"
$ ur scan --rule fixed-iv
warning[fixed-iv]: `CIPHER_IV` is a literal, so every value encrypted with it starts the same way
--> ./config/initializers/constants.rb:1:1 module's top level
= hint: make a random IV for each encryption
= see: CWE-329: Generation of Predictable IV with CBC Mode, MITRE (2024-11-19), https://cwe.mitre.org/data/definitions/329.html
scanned 1 file (no framework recognized)
fixed-iv: 1 high, 0 medium
1 finding and 0 of medium confidence
Source
CWE-329: Generation of Predictable IV with CBC Mode, MITRE (2024-11-19).