Security rules
NGB087: Insufficient password-hashing work factor
Reports password hashing / key derivation configured with constant work factors below the OWASP Password Storage Cheat Sheet minimums: PBKDF2 iterations (Web Crypto, Node crypto, CryptoJS), bcrypt cost, scrypt N·r·p (Node crypto.scrypt, including its default N=16384) and argon2 memory / time cost..
| Property | Value |
|---|---|
| Rule ID | NGB087 |
| Category | Cryptography |
| Default severity | medium |
| CWE | CWE-916, CWE-326 |
| 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 password hashing / key derivation configured with constant work factors below the OWASP Password Storage Cheat Sheet minimums: PBKDF2 iterations (Web Crypto, Node crypto, CryptoJS), bcrypt cost, scrypt N·r·p (Node crypto.scrypt, including its default N=16384) and argon2 memory / time cost.
Why it matters
Password hashes are meant to be slow so that an attacker who steals the database (or a client-side encrypted vault) can test only a few guesses per second. PBKDF2 with 1,000 or 10,000 iterations — common in old tutorials — lets a single GPU test billions of candidates; the same applies to bcrypt costs below 10 and memory-light scrypt / argon2 settings. Keys derived from passwords for client-side encryption have the same problem.
Detection behavior and supported patterns
- PBKDF2
iterationsconstant below 1,300,000 (SHA-1), 600,000 (SHA-256), 210,000 (SHA-384 / SHA-512); an unidentified hash is assessed against the SHA-256 minimum with medium confidence. Below 10,000: high severity bcrypt.hash(pw, cost),hashSync,genSalt(cost),genSaltSync(cost)with cost < 10 (bcrypt, bcryptjs)crypto.scrypt(Sync)(pw, salt, len, { N | cost, r | blockSize, p | parallelization })with N·r·p below 2^17·8; omitted options (Node default N=16384) are reported with low severityargon2.hash(pw, { memoryCost, timeCost })with memoryCost < 7168 KiB or memoryCost·timeCost < 35840- Constants include literals, arithmetic (
2 ** 14,1 << 14,Math.pow),constvalues and config-object properties
Example
await crypto.subtle.deriveBits({ name: 'PBKDF2', hash: 'SHA-256', salt, iterations: 1000 }, key, 256);Safer alternative
await crypto.subtle.deriveBits({ name: 'PBKDF2', hash: 'SHA-256', salt, iterations: 600_000 }, key, 256);Remediation
Prefer argon2id (m ≥ 19 MiB, t ≥ 2) or scrypt (N = 2^17, r = 8, p = 1). Where PBKDF2 is required, use ≥ 600,000 iterations with SHA-256 (≥ 210,000 with SHA-512); bcrypt needs a cost of at least 10. Re-hash existing passwords at the next login.
False-positive considerations
- PBKDF2 used to derive keys from high-entropy secrets (not human passwords) does not need password-grade iteration counts but is still reported; document an exception.
Known limitations
- Work factors read from environment variables or runtime configuration are not assessed.
- Hashing libraries other than the ones listed are not analyzed.
References
Run it
ngbastion explain NGB087