Insecure Random

Math.random() used for tokens, secrets, or session IDs

warningSecurityinsecure-random

Why this matters

Math.random() is not cryptographically secure. Its output is predictable — attackers can guess session tokens, reset codes, and invite links generated this way.

Example

Flaggedlib/tokens.ts
function generateToken() {
  return Math.random().toString(36).slice(2);
}
Fixedlib/tokens.ts
import { randomBytes } from "crypto";

function generateToken() {
  return randomBytes(32).toString("hex");
}

How to fix

Use crypto.randomBytes() (Node.js) or crypto.getRandomValues() (browser) for any security-sensitive random values.

Reference

In the output
Findings carry "ruleId": "insecure-random" in --json and the same id in SARIF and in the terminal.
Silence one line
// prodlint-disable-next-line insecure-random
Silence a whole file
// prodlint-disable insecure-random at the top of the file
How it works
Matches text patterns. Source on GitHub