Why it matters
Data encrypted this way can be read or patterned by an attacker who captures enough of it, so the encryption no longer keeps it confidential.
How to fix it
Use crypto.createCipheriv("aes-256-gcm", key, iv) with a random 12-byte IV per message.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
const crypto = require("crypto");
function seal(key, text) {
const cipher = crypto.createCipheriv("aes-128-ecb", key, null);
return Buffer.concat([cipher.update(text), cipher.final()]);
}const crypto = require("crypto");
function seal(key, text) {
const iv = crypto.randomBytes(12);
const cipher = crypto.createCipheriv("aes-256-gcm", key, iv);
return Buffer.concat([iv, cipher.update(text), cipher.final(), cipher.getAuthTag()]);
}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 hash (JavaScript)
JavaScriptSeverity: Medium
trustivan-javascript-weak-hash - Insecure random secret (JavaScript)
JavaScriptSeverity: Medium
trustivan-javascript-insecure-random-secret - TLS verification disabled (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-tls-verification-disabled - JWT none algorithm (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-jwt-none-algorithm - React dangerous HTML (JavaScript)
JavaScriptSeverity: Medium
trustivan-javascript-react-dangerous-html - JWT hardcoded secret (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-jwt-hardcoded-secret
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