Security rules

NGB048: Weak hash algorithm

Reports MD5, SHA-1, MD4 and RIPEMD-160 used for security purposes: crypto.subtle.digest('SHA-1', …), Web Crypto signing / HMAC keys with hash: 'SHA-1', CryptoJS MD5() / SHA1(), md5 / sha1 npm packages, and Node createHash('md5' | 'sha1') in SSR code.

Property Value
Rule ID NGB048
Category Cryptography
Default severity medium
CWE CWE-328, CWE-327, CWE-916
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 MD5, SHA-1, MD4 and RIPEMD-160 used for security purposes: crypto.subtle.digest('SHA-1', …), Web Crypto signing / HMAC keys with hash: 'SHA-1', CryptoJS MD5() / SHA1(), md5 / sha1 npm packages, and Node createHash('md5' | 'sha1') in SSR code. Only reported when the hashed value, the result or the enclosing function is named like a password, token, secret, signature, integrity check, OTP or session value; password hashing is high severity.

Why it matters

MD5 and SHA-1 have practical collision attacks, so signatures and integrity checks based on them can be forged. Hashing passwords on the client with any fast hash (and MD5/SHA-1 in particular) does not protect them: the hash becomes the password, and fast hashes are brute-forced at billions of guesses per second. Non-security checksums (cache keys, Gravatar URLs) are not reported.

Detection behavior and supported patterns

  • crypto.subtle.digest('SHA-1' | { name: 'SHA-1' }, data) (DOM SubtleCrypto)
  • crypto.subtle.importKey/generateKey(…, { name: 'HMAC' | 'RSASSA-PKCS1-v1_5' | 'RSA-PSS' | 'ECDSA', hash: 'SHA-1' }, …)
  • CryptoJS.MD5(x), CryptoJS.SHA1(x), CryptoJS.HmacMD5/HmacSHA1, default imports of md5, js-md5, blueimp-md5, crypto-js/md5, crypto-js/sha1, js-sha1
  • createHash('md5' | 'sha1') from crypto / node:crypto
  • Purpose names: password, pin, passphrase (high severity); signature, integrity, verify, hmac, token, secret, otp, nonce, csrf, session, credential names (medium)

Example

TypeScript
const hashed = CryptoJS.MD5(password).toString();this.http.post('/api/login', { username, password: hashed });

Safer alternative

TypeScript
this.http.post('/api/login', { username, password }); // server: argon2id(password)

Remediation

Use SHA-256 or stronger for integrity and signatures (crypto.subtle.digest('SHA-256', …), HMAC-SHA-256, ECDSA P-256 with SHA-256). Never hash passwords in the browser as a protection measure: send them over TLS and hash on the server with Argon2id, scrypt or bcrypt.

False-positive considerations

  • A value named like a secret that is only used as a non-security cache key can be reported.

Known limitations

  • Digests whose purpose is not visible in names (passed straight into a helper with a neutral name) are not reported.
  • Strong hashes used for password storage on the client (SHA-256 of a password) are not reported by this rule.

References

Run it

Shell
ngbastion explain NGB048