Weak random (ARCH3115)
Ce contenu n’est pas encore disponible dans votre langue.
Key typescript.security.weak-random · Severity warning · Category security · CWE CWE-338
Using a non-cryptographic PRNG like Math.random() for security-sensitive values such as tokens, keys, salts, or session ids makes those values predictable.
Incorrect
Section titled “Incorrect”function makeToken(): string { // Math.random is not cryptographically secure return Math.random().toString(36).slice(2);}Correct
Section titled “Correct”import { randomBytes } from "crypto";
function makeToken(): string { return randomBytes(32).toString("hex");}Use a cryptographically secure source like crypto.randomBytes for security-sensitive values.