no-ecb-mode
ESLint rule documentation for no-ecb-mode
📡 Live from GitHub — This documentation is fetched directly from no-ecb-mode.md and cached for 6 hours.
Keywords: ECB, encryption mode, block cipher, ECB penguin, CWE-327, security, ESLint rule, LLM-optimized CWE: CWE-327
OWASP: A02:2021-Cryptographic Failures
Disallow ECB encryption mode (use GCM or CBC instead)
Detects usage of ECB (Electronic Codebook) encryption mode which leaks data patterns. This rule is part of eslint-plugin-node-security and provides LLM-optimized error messages with fix suggestions.
🚨 Security rule | 💡 Provides suggestions | ⚠️ Set to error in recommended
Quick Summary
| Aspect | Details |
|---|---|
| CWE Reference | CWE-327 (Broken Crypto) |
| Severity | High (security vulnerability) |
| Auto-Fix | 💡 Suggests fixes (GCM, CBC) |
| Category | Security |
| ESLint MCP | ✅ Optimized for ESLint MCP integration |
| Best For | Node.js applications using symmetric encryption |
Vulnerability and Risk
Vulnerability: ECB mode encrypts identical plaintext blocks to identical ciphertext blocks. This means patterns in the plaintext are preserved in the ciphertext, leaking information about the data structure.
Risk: The famous "ECB Penguin" demonstrates this perfectly - an encrypted image still shows the original image's structure. This weakness can reveal message lengths, patterns, and repeated data to attackers.
Rule Details
This rule detects ECB mode usage in crypto.createCipheriv() calls (e.g., aes-128-ecb, aes-256-ecb) and suggests using GCM or CBC mode instead.
Why This Matters
| Risk | Impact | Solution |
|---|---|---|
| 🎨 Pattern Leakage | Data patterns visible in ciphertext | Use GCM or CBC mode |
| 📊 Block Analysis | Repeated blocks reveal repeated data | Use authenticated encryption |
| 🔒 Compliance | Fails security audits and pen tests | Replace all ECB usage |
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
allowInTests | boolean | false | Allow ECB mode in test files |
{
rules: {
'node-security/no-ecb-mode': ['error', {
allowInTests: false
}]
}
}Examples
❌ Incorrect
import crypto from 'crypto';
// ECB mode leaks patterns - HIGH risk
const cipher = crypto.createCipheriv('aes-128-ecb', key, null);
// AES-256-ECB - still insecure despite key size
const strongKeyEcb = crypto.createCipheriv('aes-256-ecb', key, null);✅ Correct
import crypto from 'crypto';
// GCM mode - authenticated encryption (recommended)
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
// CBC mode with random IV
const cbcCipher = crypto.createCipheriv('aes-256-cbc', key, iv);
// ChaCha20-Poly1305 - authenticated stream cipher
const chachaCipher = crypto.createCipheriv('chacha20-poly1305', key, iv);The ECB Penguin

The "ECB Penguin" is a famous example showing how ECB mode preserves patterns. The original Tux penguin image, when encrypted with ECB mode, still shows the penguin's outline because identical pixel blocks produce identical ciphertext blocks.
Security Impact
| Vulnerability | CWE | OWASP | CVSS | Impact |
|---|---|---|---|---|
| Broken Crypto | 327 | A02:2021 | 5.9 Medium | Pattern leakage |
| Information Exposure | 200 | A02:2021 | 5.3 Medium | Data structure revealed |
Migration Guide
Phase 1: Discovery
{
rules: {
'node-security/no-ecb-mode': 'warn'
}
}Phase 2: Replacement
// Replace ECB with GCM
crypto.createCipheriv('aes-256-ecb', key, null); // ❌ Before
crypto.createCipheriv('aes-256-gcm', key, iv); // ✅ AfterPhase 3: Enforcement
{
rules: {
'node-security/no-ecb-mode': 'error'
}
}Related Rules
no-weak-cipher-algorithm- Detect weak encryption algorithmsno-static-iv- Detect hardcoded initialization vectorsno-deprecated-cipher-method- Detect deprecated cipher methods
Known False Negatives
Dynamic Mode Strings
Why: Dynamic strings cannot be analyzed statically.
// ❌ NOT DETECTED
const mode = config.cipherMode;
crypto.createCipheriv(`aes-256-${mode}`, key, iv);Mitigation: Use constants for cipher specifications.
Further Reading
- ECB Mode Visualization - Cloudflare article on ECB weaknesses
- Block Cipher Modes - Wikipedia comparison of modes
- CWE-327: Broken Crypto Algorithm - Official CWE entry