Static IV (ARCH3114)
Ce contenu n’est pas encore disponible dans votre langue.
Key typescript.security.static-iv · Severity error · Category security · CWE CWE-329
Passing a constant or zero IV/nonce to a cipher destroys semantic security across messages encrypted with the same key and breaks CBC/CTR/GCM modes.
Incorrect
Section titled “Incorrect”import { createCipheriv } from "crypto";
const iv = Buffer.alloc(16, 0); // static zero IVconst cipher = createCipheriv("aes-256-cbc", key, iv);Correct
Section titled “Correct”import { createCipheriv, randomBytes } from "crypto";
const iv = randomBytes(16); // unique per encryptionconst cipher = createCipheriv("aes-256-cbc", key, iv);// store the iv alongside the ciphertextGenerate a random, unique IV with randomBytes for every encryption operation.