Math.random produces a value that is named as a token, password or other secret
What it finds
const token = Math.random().toString(36).slice(2): Math.random is not meant for secrets. Its output can be predicted from earlier values, so tokens, passwords, nonces and session ids made from it can be guessed. crypto.getRandomValues and crypto.randomUUID give values that cannot.
A call of the global Math.random is reported when the variable, property or assignment target it goes into, or the function it is in, has a name with token, secret, password, nonce, salt, otp, session, apikey or csrf in it, ignoring case.
From the rule's source, predictable_secret.rs.
function makeToken() { return Math.random().toString(36).slice(2);tx0 reports: makeToken is made with Math.random}const sessionId = Math.random();tx0 reports: sessionId is made with Math.randomconst jitter = Math.random() * 100; Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:predictable-secret" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:predictable-secret] reason="..."tx0 explain tx0/ts:predictable-secret shows the same in the terminal. Found a false positive? Report it.