ESLint InterlaceESLint Interlace
Plugin: node-securityRules

no-weak-hash-algorithm

ESLint rule documentation for no-weak-hash-algorithm

📡 Live from GitHub — This documentation is fetched directly from no-weak-hash-algorithm.md and cached for 6 hours.

Keywords: MD5, SHA-1, MD4, RIPEMD, weak hash, cryptography, CWE-327, security, ESLint rule, LLM-optimized CWE: CWE-327
OWASP: A02:2021-Cryptographic Failures

Disallow weak hash algorithms (MD5, MD4, SHA-1, RIPEMD)

Detects usage of weak hash algorithms (MD5, MD4, SHA-1, RIPEMD) in Node.js crypto operations. 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 (SHA-256, SHA-512, SHA-3)
CategorySecurity
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForNode.js applications using crypto.createHash()

Vulnerability and Risk

Vulnerability: MD5, MD4, SHA-1, and RIPEMD are cryptographically broken hash algorithms. They are vulnerable to collision attacks which allow attackers to create different messages with the same hash.

Risk: Using weak hash algorithms for security-sensitive operations (password hashing, digital signatures, file integrity) can allow attackers to forge signatures, create colliding files, or perform preimage attacks.

Rule Details

This rule detects usage of weak hash algorithms in crypto.createHash() calls and suggests secure alternatives like SHA-256, SHA-512, or SHA-3.

Why This Matters

RiskImpactSolution
🔓 Hash CollisionsAttackers can create colliding messagesMigrate to SHA-256, SHA-512, or SHA-3
📜 Signature ForgeryDigital signatures can be forgedUse SHA-256 minimum for signatures
🔒 ComplianceFails PCI-DSS, NIST, and SOC2 requirementsReplace all weak hash usage

Configuration

OptionTypeDefaultDescription
additionalWeakAlgorithmsstring[][]Additional weak algorithms to flag
allowInTestsbooleanfalseAllow weak hashes in test files
{
  rules: {
    'node-security/no-weak-hash-algorithm': ['error', {
      additionalWeakAlgorithms: ['whirlpool'],
      allowInTests: false
    }]
  }
}

Examples

❌ Incorrect

import crypto from 'crypto';

// MD5 - completely broken
const hash = crypto.createHash('md5').update(data).digest('hex');

// SHA-1 - collision attacks demonstrated
const sha1Hash = crypto.createHash('sha1').update(data).digest('hex');

// MD4 - severely broken
const md4Hash = crypto.createHash('md4').update(data).digest('hex');

// RIPEMD - deprecated
const ripemdHash = crypto.createHash('ripemd160').update(data).digest('hex');

✅ Correct

import crypto from 'crypto';

// SHA-256 - recommended for most use cases
const hash = crypto.createHash('sha256').update(data).digest('hex');

// SHA-512 - stronger, use for high-security needs
const sha512Hash = crypto.createHash('sha512').update(data).digest('hex');

// SHA-3 - newest, NIST-approved
const sha3Hash = crypto.createHash('sha3-256').update(data).digest('hex');

Security Impact

VulnerabilityCWEOWASPCVSSImpact
Broken Crypto327A02:20217.5 HighHash collision attacks
Weak Hash Algorithm328A02:20215.3 MediumReduced cryptographic strength

Migration Guide

Phase 1: Discovery

{
  rules: {
    'node-security/no-weak-hash-algorithm': 'warn'
  }
}

Phase 2: Replacement

// Replace MD5/SHA-1 with SHA-256
crypto.createHash('md5'); // ❌ Before
crypto.createHash('sha256'); // ✅ After

crypto.createHash('sha1'); // ❌ Before
crypto.createHash('sha256'); // ✅ After

Phase 3: Enforcement

{
  rules: {
    'node-security/no-weak-hash-algorithm': 'error'
  }
}

Known False Negatives

The following patterns are not detected due to static analysis limitations:

Dynamic Algorithm Names

Why: Dynamic strings cannot be analyzed statically.

// ❌ NOT DETECTED - Dynamic algorithm
const algorithm = getAlgorithm();
crypto.createHash(algorithm);

Mitigation: Use constants for algorithm names.

Variable Reassignment

Why: Cross-function data flow is not tracked.

// ❌ NOT DETECTED - Variable algorithm
let algo = 'md5';
crypto.createHash(algo);

Mitigation: Apply linting at integration points.

Further Reading

On this page

No Headings