Security rules
NGB065: Broken or weak cipher
Reports encryption with broken or obsolete ciphers and modes: DES, RC4, RC2 (high), Triple DES, Blowfish, CAST, IDEA and ECB mode (medium) in Node createCipheriv() / createDecipheriv(), CryptoJS (CryptoJS.DES / TripleDES / RC4 / RC4Drop, mode: CryptoJS.mode.ECB) and node-forge (forge.cipher.createCipher('DES-…' | 'AES-ECB', key)), plus the deprecated Node createCipher() / createDecipher() API (no IV, MD5-based key derivation)..
| Property | Value |
|---|---|
| Rule ID | NGB065 |
| Category | Cryptography |
| Default severity | high |
| CWE | CWE-327 |
| Built-in presets | recommended: error, strict: error |
Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.
What it checks
Reports encryption with broken or obsolete ciphers and modes: DES, RC4, RC2 (high), Triple DES, Blowfish, CAST, IDEA and ECB mode (medium) in Node createCipheriv() / createDecipheriv(), CryptoJS (CryptoJS.DES / TripleDES / RC4 / RC4Drop, mode: CryptoJS.mode.ECB) and node-forge (forge.cipher.createCipher('DES-…' | 'AES-ECB', key)), plus the deprecated Node createCipher() / createDecipher() API (no IV, MD5-based key derivation).
Why it matters
DES keys are brute-forced in hours, RC4 keystreams are biased enough to recover plaintext, 64-bit block ciphers leak plaintext after a few gigabytes under one key (Sweet32), and ECB mode shows which blocks are equal — the classic 'ECB penguin'. crypto.createCipher() derives the key from a password with a single MD5 round and uses no IV, so the same plaintext always produces the same ciphertext.
Detection behavior and supported patterns
createCipheriv('des-ede3-cbc' | 'des-cbc' | 'rc4' | 'bf-cbc' | 'aes-256-ecb' …, key, iv)andcreateDecipheriv(…)fromcrypto/node:crypto(named, namespace, default andrequire()bindings)crypto.createCipher(alg, password)/createDecipher()(deprecated) — mediumCryptoJS.DES.encrypt(),CryptoJS.TripleDES.encrypt(),CryptoJS.RC4.encrypt(),{ mode: CryptoJS.mode.ECB }forge.cipher.createCipher('DES-CBC' | '3DES-CBC' | 'AES-ECB', key)
Example
const cipher = createCipheriv('des-ede3-cbc', key, iv);Safer alternative
const iv = randomBytes(12);const cipher = createCipheriv('aes-256-gcm', key, iv);Remediation
Use an authenticated cipher: AES-256-GCM or ChaCha20-Poly1305 (createCipheriv('aes-256-gcm', key, randomBytes(12)), Web Crypto AES-GCM) with a random IV per message, and derive keys with a real KDF (scrypt, PBKDF2, HKDF) instead of createCipher().
False-positive considerations
- Decrypting legacy data for migration is reported; once re-encrypted with AES-GCM the code can be removed or the finding excepted.
Known limitations
- Algorithm names must be compile-time constants; names read from configuration are not resolved.
- Unauthenticated modes (AES-CBC, AES-CTR without a MAC) are not reported.
References
Run it
ngbastion explain NGB065