Why it matters
Someone who sees a few outputs can predict the token, password or key this value becomes.
How to fix it
Use crypto.randomBytes or crypto.randomUUID in Node.js, or crypto.getRandomValues in the browser.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
function newResetToken() {
const resetToken = Math.random().toString(36).slice(2);
return resetToken;
}const crypto = require("crypto");
function newResetToken() {
const resetToken = crypto.randomBytes(32).toString("hex");
return resetToken;
}
function jitter() {
const delay = Math.random() * 500;
return delay;
}What TrustIvan reads
Runs on repository scans of JavaScript source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- Weak cipher (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-weak-cipher - JWT none algorithm (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-jwt-none-algorithm - Weak hash (JavaScript)
JavaScriptSeverity: Medium
trustivan-javascript-weak-hash - JWT hardcoded secret (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-jwt-hardcoded-secret - TLS verification disabled (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-tls-verification-disabled - CORS reflected origin with credentials (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-cors-reflected-origin-with-credentials
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation