Javascript Hardcoded Aead Nonce
Description
This vulnerability detector identifies hardcoded AEAD (Authenticated Encryption with Associated Data) nonces in JavaScript code. Using hardcoded nonces in AEAD encryption schemes completely breaks the security model since nonces must be unique and unpredictable - reusing nonces allows attackers to recover encryption keys or plaintext data.
Detection Strategy
• Scans JavaScript source code for AEAD encryption operations (such as AES-GCM, ChaCha20-Poly1305, or similar authenticated encryption modes)
• Identifies when nonce/IV parameters are set to static, hardcoded values instead of being randomly generated
• Reports violations when AEAD functions use literal strings, fixed byte arrays, or other constant values as nonces
• Triggers alerts for cryptographic library calls where the nonce parameter contains predictable or reused values
Vulnerable code example
const crypto = require('crypto');
function encryptData(key, data) {
// VULNERABLE: hardcoded nonce creates identical ciphertext for same plaintext
const cipher = crypto.createCipheriv('aes-256-gcm', key, '000000000000');
return Buffer.concat([cipher.update(data), cipher.final()]);
}✅ Secure code example
const crypto = require('crypto');
function encryptData(key, data) {
const nonce = crypto.randomBytes(12); // SAFE: random nonce prevents identical ciphertext
const cipher = crypto.createCipheriv('aes-256-gcm', key, nonce);
return Buffer.concat([nonce, cipher.update(data), cipher.final(), cipher.getAuthTag()]);
}Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.