← all rules

code/js-insecure-random

Insecure randomness: Math.random() in security context

mediumCode regexweak-cryptoCWE-338js

What it detects

Math.random() is not cryptographically secure. For tokens/session IDs use crypto.randomBytes or crypto.randomUUID.

How it runs

Applied line-by-line via a tagged regex with language-specific gating. Comments are skipped. Designed for high-confidence patterns where AST parsing would be overkill.

Found a false positive or want this rule tuned? File an issue. You can also suppress per-repo via a .repoguardignore line.