An RSA or DSA key pair is generated with fewer than 2048 bits

tx0/ts:weak-key-sizerecommendedwarningsecurity, cwe-326

What it finds

RSA and DSA keys shorter than 2048 bits can be factored or broken with resources that are within reach today, so signatures made with them can be forged and data encrypted with them read.

Reported are calls of Node's generateKeyPair and generateKeyPairSync for "rsa", "rsa-pss" or "dsa" whose modulusLength is a literal below 2048.

From the rule's source, weak_key_size.rs.

Example from the rule's tests
import { generateKeyPairSync } from "crypto";export const weak = generateKeyPairSync("rsa", { modulusLength: 1024 });tx0 reports: a key of 1024 bits is too shortexport const strong = generateKeyPairSync("rsa", { modulusLength: 4096 });export const curve = generateKeyPairSync("ec", { namedCurve: "P-256" });
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:weak-key-size" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:weak-key-size] reason="..."

tx0 explain tx0/ts:weak-key-size shows the same in the terminal. Found a false positive? Report it.