A cipher class took its randomness source as a constructor argument and trusted it. Hand it a predictable generator and the nonces repeat, which is the one thing AES-GCM cannot survive.
What goes wrong
The class needed a source of randomness, so it accepted one as a constructor parameter and stored it. Reasonable on the surface, and clean by the usual standards: it is dependency injection, it is easy to test. The problem is that the nonce for every encryption now comes from whatever the caller handed over, and the class never checks what that was.
Feed it a generator seeded with a constant, or one that was already drained, and you get repeated nonces. Under AES-GCM a repeated nonce with the same key is catastrophic. An attacker who sees two ciphertexts under one nonce can recover the authentication key and forge messages, and the keystream reuse leaks the plaintext. This is a full break of the mode, not a slight weakening of it.
The wider point: a security primitive should own the ingredients that make it secure. Randomness is one of them. Accepting it from outside turns an internal invariant into a caller's promise, and callers break promises.
The pattern
class SecureBox:
def __init__(self, rng):
self.rng = rng # trusts whatever is passed in
def seal(self, key, plaintext):
nonce = self.rng.bytes(12) # predictable if rng is
return aes_gcm_encrypt(key, nonce, plaintext)class SecureBox:
def __init__(self):
self.rng = system_secure_random() # owned internally
def seal(self, key, plaintext):
nonce = self.rng.bytes(12)
return aes_gcm_encrypt(key, nonce, plaintext)Grounding and reachability were confirmed. The exploit-path gate would not conclude without the calling code, so the finding was held and an evidence request was raised instead of being reported as fact.
Why it matters to you
If this ships in a wallet or a messaging path, one bad caller turns every message into a decryptable one. A test harness left wired into production. A well-meaning deterministic mode for reproducible builds. An attacker who reaches the injection point. You will not catch it in a unit test either, because the unit test is exactly the code that supplies the weak generator.
Check your own code
- Grep for constructors or factories that accept a random or entropy source as a parameter.
- Confirm nonce and IV generation uses a platform CSPRNG created inside the primitive, not a passed-in one.
- For AES-GCM or ChaCha20-Poly1305, verify nonces are unique per key and never caller-seeded.