Why it matters
With a suitable class on the classpath, loading them runs code chosen by the caller.
How to fix it
Accept JSON bound to a concrete class instead. If Java serialisation cannot be avoided, install an ObjectInputFilter that allows only the expected classes.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
import java.io.ObjectInputStream;
import javax.servlet.http.HttpServletRequest;
public class Bad {
public Object restore(HttpServletRequest request) throws Exception {
ObjectInputStream in = new ObjectInputStream(request.getInputStream());
return in.readObject();
}
}import com.fasterxml.jackson.databind.ObjectMapper;
import javax.servlet.http.HttpServletRequest;
public class Ok {
public static class State { public java.util.List<String> items; }
public Object restore(HttpServletRequest request) throws Exception {
return new ObjectMapper().readValue(request.getInputStream(), State.class);
}
}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
- XSS from request input (Java)
JavaSeverity: High
trustivan-java-taint-xss - Open redirect from request input (Java)
JavaSeverity: Medium
trustivan-java-taint-open-redirect - SSRF from request input (Java)
JavaSeverity: High
trustivan-java-taint-ssrf - LDAP injection from request input (Java)
JavaSeverity: High
trustivan-java-taint-ldap-injection - Path traversal from request input (Java)
JavaSeverity: High
trustivan-java-taint-path-traversal - XPath injection from request input (Java)
JavaSeverity: High
trustivan-java-taint-xpath-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