R01 Weak Randomness
What this means
SiteShadow flagged use of non-cryptographic randomness for security-sensitive values (tokens, reset links, session IDs, invitation codes, API keys, nonce/IV generation).
Why it matters
Predictable randomness can enable guessing attacks and token compromise.
- Account takeover: attackers can guess password reset or invite tokens.
- Session hijacking: predictable session IDs are catastrophic.
- Crypto failures: weak nonces/IVs can break encryption guarantees.
Safer examples
1) Use a cryptographically secure RNG
import { randomBytes } from "node:crypto";
const token = randomBytes(32).toString("hex");
import secrets
token = secrets.token_urlsafe(32)
2) Don't use Math.random() / random() for secrets
Those are fine for UI effects and simulations, not auth tokens.
3) Keep token length sufficient
Use at least 128 bits of entropy for security tokens (often 16+ bytes).
How SiteShadow detects it (high level)
- Detects calls to non-crypto RNG APIs near security-sensitive variable names/uses.
- Flags "random token" construction patterns that don't use secure RNGs.
References
- CWE-338: https://cwe.mitre.org/data/definitions/338.html
---