Math.random() is not cryptographically secure. Use crypto.randomUUID() or crypto.getRandomValues() for tokens, IDs, and security-sensitive values. [CWE-338]
Why This Matters
prevents predictable tokens that enable session hijacking or enumeration attacks
Impact: CRITICAL (prevents predictable tokens that enable session hijacking or enumeration attacks)
Math.random() uses a pseudo-random number generator (PRNG) that is not cryptographically secure. Its output can be predicted if an attacker observes enough values, and some engines seed it with low-entropy sources. When used to generate session tokens, CSRF tokens, password reset links, unique IDs for access control, or nonces, an attacker can predict or brute-force subsequent values.
Incorrect (using Math.random() for security-sensitive values):