Using Checkmarx, this one page has multiple uses of the "request.getParameterNames()" and is flagged by Checkmarx as "CGI_Reflected_XSS_All_Clients" (Query Name). The page is "error.jsp" so it is a common page that is used across multiple apps in my company. This page gets displayed when an unexpected error occurs. Why this way? who knows, best to not show it and just log it out instead. I'm pretty new to the fixing code being reported as vulnerable by Checkmarx.
<h3>Request Parameters</h3>
<pre>
<%
lEnum = request.getParameterNames();
while(lEnum.hasMoreElements())
{
String key = (String)lEnum.nextElement();
String[] paramValues = request.getParameterValues(key);
for(int i = 0; i < paramValues.length; i++)
{
out.println(" " + key + " : " + paramValues[i]);
}
}
%>
</pre>
The values output to the page need to be escaped for HTML. Replace quotes, brackets, and ampersands with their entities. This can be done with libraries such as Guava like: