Why it matters
Equal plaintext blocks encrypt to equal ciphertext blocks, which reveals the structure of the data.
How to fix it
Use Cipher.getInstance("AES/GCM/NoPadding") with a random 12-byte IV.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
import javax.crypto.Cipher;
public class Bad {
public Cipher cipher() throws Exception {
return Cipher.getInstance("AES/ECB/PKCS5Padding");
}
}import javax.crypto.Cipher;
public class Ok {
public Cipher cipher() throws Exception {
return Cipher.getInstance("AES/GCM/NoPadding");
}
}What TrustIvan reads
Runs on repository scans of Java 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 (Java)
JavaSeverity: High
trustivan-java-weak-cipher - Insecure random secret (Java)
JavaSeverity: Medium
trustivan-java-insecure-random-secret - XXE XML input factory (Java)
JavaSeverity: High
trustivan-java-xxe-xml-input-factory - Trust all certificates (Java)
JavaSeverity: High
trustivan-java-trust-all-certificates - XXE document builder (Java)
JavaSeverity: High
trustivan-java-xxe-document-builder - Hostname verification disabled (Java)
JavaSeverity: High
trustivan-java-hostname-verification-disabled
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