Security rules
NGB088: Insufficient asymmetric key size
Reports generation of RSA, DSA and Diffie-Hellman keys smaller than 2048 bits and elliptic-curve keys on curves below 224 bits: Web Crypto generateKey() (RSA-OAEP, RSA-PSS, RSASSA-PKCS1-v1_5), Node crypto.generateKeyPair(Sync)() / generateKeySync(), crypto.createDiffieHellman(primeLength) and node-forge pki.rsa.generateKeyPair()..
| Property | Value |
|---|---|
| Rule ID | NGB088 |
| Category | Cryptography |
| Default severity | medium |
| CWE | 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 generation of RSA, DSA and Diffie-Hellman keys smaller than 2048 bits and elliptic-curve keys on curves below 224 bits: Web Crypto generateKey() (RSA-OAEP, RSA-PSS, RSASSA-PKCS1-v1_5), Node crypto.generateKeyPair(Sync)() / generateKeySync(), crypto.createDiffieHellman(primeLength) and node-forge pki.rsa.generateKeyPair().
Why it matters
RSA-1024 and DH-1024 are within reach of well-funded attackers, and 512/768-bit keys have been factored publicly; NIST disallowed keys below 2048 bits (112-bit security) for new signatures and key establishment. Keys generated in the browser or on the SSR server protect signatures, encrypted payloads and key exchange for their whole lifetime — a weak key cannot be fixed later for data already protected with it.
Detection behavior and supported patterns
crypto.subtle.generateKey({ name: 'RSA-OAEP' | 'RSA-PSS' | 'RSASSA-PKCS1-v1_5', modulusLength }, …)with a constantmodulusLength< 2048generateKeyPair(Sync)('rsa' | 'rsa-pss' | 'dsa', { modulusLength })< 2048,('dh', { primeLength })< 2048,('ec', { namedCurve })on a curve below 224 bits (secp112/128/160/192, prime192v1, P-192, brainpoolP160/192, small binary curves)createDiffieHellman(primeLength)with a constant length < 2048forge.pki.rsa.generateKeyPair(bits)/({ bits })< 2048- Keys ≤ 1024 bits: high severity; 1025–2047: medium
Example
await crypto.subtle.generateKey({ name: 'RSA-OAEP', modulusLength: 1024, publicExponent: new Uint8Array([1, 0, 1]), hash: 'SHA-256' }, true, ['encrypt', 'decrypt']);Safer alternative
await crypto.subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, false, ['sign', 'verify']);Remediation
Use RSA keys of at least 2048 bits (3072 for protection beyond 2030), Diffie-Hellman groups of at least 2048 bits, or — preferably — elliptic curves P-256 / Ed25519 / X25519.
False-positive considerations
- Throwaway keys in test helpers outside excluded test folders are reported; exclude those files.
Known limitations
- Key sizes of imported keys (
importKey, PEM files, certificates) are not visible. - Sizes read from configuration at runtime are not assessed.
References
Run it
ngbastion explain NGB088