highCWE-329A02:2021

Static IV/Nonce

Using a hardcoded or constant Initialization Vector (IV) or nonce for encryption defeats the purpose of the IV and allows attackers to detect patterns and decrypt data.

How It Works

An IV (Initialization Vector) or nonce ensures that encrypting the same plaintext with the same key produces different ciphertext each time. When the IV is hardcoded, constant, or predictable, this property is lost. In CBC mode, a static IV allows attackers to detect when the same message is encrypted twice. In CTR mode, reusing a nonce with the same key allows trivial decryption — XORing two ciphertexts encrypted with the same key and nonce cancels out the keystream, revealing the XOR of the two plaintexts. In GCM mode, nonce reuse is catastrophic — it allows the attacker to recover the authentication key and forge encrypted messages.

Vulnerable Code
const crypto = require('crypto');
const STATIC_IV = Buffer.from('1234567890abcdef');
function encrypt(text, key) {
  const cipher = crypto.createCipheriv('aes-256-cbc', key, STATIC_IV);
  let encrypted = cipher.update(text, 'utf8', 'hex');
  encrypted += cipher.final('hex');
  return encrypted;
}
Secure Code
const crypto = require('crypto');
function encrypt(text, key) {
  const iv = crypto.randomBytes(16);
  const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
  let encrypted = cipher.update(text, 'utf8', 'hex');
  encrypted += cipher.final('hex');
  return iv.toString('hex') + ':' + encrypted;
}

Real-World Example

In 2020, researchers discovered that the Zoom video conferencing application used a single AES-128 key in ECB mode with no IV for encrypting meeting content. This allowed participants and potential eavesdroppers to detect patterns in video streams. Zoom subsequently upgraded to AES-256-GCM with proper IV generation.

How to Prevent It

  • Generate a cryptographically random IV with crypto.randomBytes(16) for every encryption
  • Prepend the IV to the ciphertext so it is available for decryption
  • Never hardcode, derive from a timestamp, or reuse IVs across encryptions
  • Use AES-GCM which makes nonce uniqueness requirements explicit

Affected Technologies

Node.jsPythonJavaGoC#

Data Hogo detects this vulnerability automatically.

Scan Your Repo Free

Related Vulnerabilities