# VNX-329: Predictable IV derived from the key or a non-cryptographic generator

Reports block-cipher IVs that are the key (or a slice of it) or come from a non-cryptographic generator or the clock, in Python, Java, Kotlin.

| Field | Value |
|---|---|
| Rule ID | `VNX-329` |
| Severity | High |
| SARIF level | `error` |
| Kind | `sast` |
| Languages | Go, Java, Kotlin, JavaScript / TypeScript, Python |
| CWE | [CWE-329](https://cwe.mitre.org/data/definitions/329.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:H/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:H/DI:H/EX:H/EC:N/P:H` |
| Tags | `crypto` `iv-reuse` `predictable-iv` `cwe-329` |
| Source | [`internal/sast/rules/vnx-329.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-329.rego) |

## Overview

VNX-329 maps to [CWE-329: Generation of Predictable IV with CBC Mode](https://cwe.mitre.org/data/definitions/329.html). It reports an IV or nonce that is predictable because it is derived from the encryption key, drawn from a non-cryptographic generator, or built from the clock.

## Why this matters

A predictable CBC IV allows chosen-plaintext attacks (BEAST is the famous one). Using the key as the IV is worse: an attacker who can get one chosen ciphertext decrypted recovers the key itself.

## What gets flagged

```python
# FLAGGED: the IV is the key
AES.new(key, AES.MODE_CBC, key)
iv = key[:16]
# FLAGGED: the IV comes from the random module
iv = random.randbytes(16)
```

```java
// FLAGGED
new IvParameterSpec(keyBytes)
byte[] ivBytes = Arrays.copyOf(secretKey, 16);
rnd.nextBytes(iv);   // rnd is a java.util.Random
```

```go
// FLAGGED
cipher.NewCBCEncrypter(block, key[:aes.BlockSize])
rand.Read(iv)        // math/rand
```

```javascript
// FLAGGED
crypto.createCipheriv('aes-256-cbc', key, key.slice(0, 16));
```

## What is not flagged

- IVs from `os.urandom`, `secrets`, `get_random_bytes`, `SecureRandom`, `crypto/rand`, `randomBytes` or `getRandomValues`.
- IVs read from the ciphertext (`blob[:16]`).
- Constant IVs, which [VNX-CRYPTO-010](/sast/rules/vnx-crypto-010.md) and [VNX-JAVA-020](/sast/rules/vnx-java-020.md) report.
- Names that only contain the letters (`keys`, `keyword`, `keystore`), comments, string literals and test files.

## Remediation

Generate a fresh IV for every message from a CSPRNG and send it with the ciphertext, or use an AEAD mode with a random or counter nonce that is never reused under the same key.

## References

- [CWE-329: Generation of Predictable IV with CBC Mode](https://cwe.mitre.org/data/definitions/329.html)
- [NIST SP 800-38A, Appendix C](https://csrc.nist.gov/publications/detail/sp/800-38a/final)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-329
// nosec vnx-329
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-329 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
