ESLint InterlaceESLint Interlace
Plugin: node-securityRules

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

AspectDetails
CWE ReferenceCWE-327 (Broken Crypto)
SeverityHigh (security vulnerability)
Auto-Fix💡 Suggests fixes (GCM, CBC)
CategorySecurity
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForNode.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

RiskImpactSolution
🎨 Pattern LeakageData patterns visible in ciphertextUse GCM or CBC mode
📊 Block AnalysisRepeated blocks reveal repeated dataUse authenticated encryption
🔒 ComplianceFails security audits and pen testsReplace all ECB usage

Configuration

OptionTypeDefaultDescription
allowInTestsbooleanfalseAllow 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

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

VulnerabilityCWEOWASPCVSSImpact
Broken Crypto327A02:20215.9 MediumPattern leakage
Information Exposure200A02:20215.3 MediumData 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); // ✅ After

Phase 3: Enforcement

{
  rules: {
    'node-security/no-ecb-mode': 'error'
  }
}

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

On this page

No Headings