This question was flagged as a duplicate, but it is not, and the question referenced did not address javascript injection at all. And both answers provided below so far completely ignore the fact that I AM using the escapeXML attribute of the c:out tag, but it doesn't work. The issue is that javascript does not necessarily contain ANY HTML characters. I need to be able to prevent runnable javascript from being injected into my JSP code.
The organization that I develop for runs every web application through a code scanner to locate any potential vulnerabilities that may be contained in the code. We've had several found simply because our application was initially deployed long before XSS vulnerabilities were a thing. Normally these issues are easy to eliminate, since there is a significant body of work on Cross-site scripting and various injection techniques.
Technologies are: Java 8, jsp, Spring, Javascript, Oracle
However, I have come across a vulnerability that I can find very little discussion on...escaping javascript injection.
We have a url that takes a string as a RequestParam: testapp.com?stringValue=test
Our vulnerability checker injects an alert into the RequestParam: testapp.com?stringValue=test'+alert(6853)+'
The jsp page in question uses <c:out value="${stringValue}" escapeXML="true"/> to output the string in question. When the page renders, we get a javascript alert dialog that pops up on the page, indicating that the javascript injection was successful.
In this particular case, the data contained in stringValue is one of two expected values, and so it is easy to just check the RequestParam in the controller and if the value does not match one of the two expected values, throw an InvalidParameterException. But we have several cases where a string-based RequestParam can be anything, so the solution used above would not work.
I have spent several days researching this issue, and while there are plenty of suggestions as to how to eliminate injected HTML in a jsp application, I can find very little useful information about eliminating injected javascript, which to me seems like a much bigger issue, as injected javascript could do malicious things to a web application.
Does anyone have any useful recommendations as to how to resolve this issue?