Why it matters
If the response is served as HTML, markup in the value runs as script in the user's browser.
How to fix it
Render the value through a template that escapes by default (Thymeleaf th:text, JSP c:out), or encode it with the OWASP Java Encoder (Encode.forHtml) before writing.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Bad extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException {
String name = request.getParameter("name");
response.setContentType("text/html");
response.getWriter().println("<h1>Hello " + name + "</h1>");
}
}import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.owasp.encoder.Encode;
public class Ok extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException {
String name = Encode.forHtml(request.getParameter("name"));
response.setContentType("text/html");
response.getWriter().println("<h1>Hello " + name + "</h1>");
}
}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
- SSRF from request input (Java)
JavaSeverity: High
trustivan-java-taint-ssrf - Deserialization from request input (Java)
JavaSeverity: High
trustivan-java-taint-deserialization - Path traversal from request input (Java)
JavaSeverity: High
trustivan-java-taint-path-traversal - Open redirect from request input (Java)
JavaSeverity: Medium
trustivan-java-taint-open-redirect - Command injection from request input (Java)
JavaSeverity: High
trustivan-java-taint-command-injection - LDAP injection from request input (Java)
JavaSeverity: High
trustivan-java-taint-ldap-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