Why it matters
Any operand that comes from outside the program can add arguments, and with a shell in the command, whole commands.
How to fix it
Use ProcessBuilder with each argument as its own list element.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
public class Bad {
public Process archive(String directory) throws Exception {
return Runtime.getRuntime().exec("tar czf backup.tgz " + directory);
}
}public class Ok {
public Process archive(String directory) throws Exception {
return new ProcessBuilder("tar", "czf", "backup.tgz", directory).start();
}
}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 RSA key (Java)
JavaSeverity: Medium
trustivan-java-weak-rsa-key - Template injection from request input (Java)
JavaSeverity: High
trustivan-java-taint-template-injection - Insecure TLS protocol (Java)
JavaSeverity: Medium
trustivan-java-insecure-tls-protocol - Regex injection from request input (Java)
JavaSeverity: Medium
trustivan-java-taint-regex-injection - JWT unsigned parse (Java)
JavaSeverity: High
trustivan-java-jwt-unsigned-parse - NoSQL injection from request input (Java)
JavaSeverity: High
trustivan-java-taint-nosql-injection
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