A digest is computed with MD5, SHA-1 or another algorithm with known collisions
What it finds
MD5 and SHA-1 have practical collision attacks, and MD4 and MD2 are broken entirely. A digest made with them does not prove that data is unchanged or authentic, and fast hashes of any kind are unsuited to storing passwords.
Reported are createHash and createHmac from Node's crypto module with one of these algorithm names as a literal, and crypto.subtle.digest with "SHA-1". A hash used only as a cache key or checksum is not a security problem, which is why the rule is not in the default tier.
From the rule's source, broken_hash_function.rs.
import crypto from "crypto";export function digests(data: string, key: string) { const a = crypto.createHash("md5").update(data).digest("hex");tx0 reports: md5 has known collision attacks const b = crypto.createHmac("SHA1", key);tx0 reports: SHA1 has known collision attacks const c = crypto.createHash("sha256"); const d = globalThis.crypto.subtle.digest("SHA-1", new Uint8Array());tx0 reports: SHA-1 has known collision attacks const e = hash.digest("sha1"); return [a, b, c, d, e];}declare const hash: { digest(name: string): string }; 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:
[rules]
"tx0/ts:broken-hash-function" = "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:broken-hash-function] reason="..."tx0 explain tx0/ts:broken-hash-function shows the same in the terminal. Found a false positive? Report it.