I get this issue with CheckMarx security scan:
Method
exec
at line 69 ofweb\src\main\java\abc\web\actions\HomeAction.java
gets user input for theCNF_KEY_COSN
element. This element’s value then flows through the code without being properly sanitized or validated and is eventually displayed to the user in methodlogException
at line 905 ofweb\src\main\java\gov\abc\external\info\ServiceHelper.java
. This may enable a Cross-Site-Scripting attack.
Line 69 of HomeAction.java
:
String cosn = (String) request.getParameter(CNF_KEY_CON);
Line 905 in ServiceHelper.java
just logs the error:
private static void logException(InfoServiceException exception, String message) {
String newMessage = message + ": " + exception.getMessageForLogging();
try {
log.error(newMessage, exception);
} catch (Exception e) {
// fallback to console
System.out.println("error logging exception ->");
e.printStackTrace(System.out);
System.out.println("exception ->");
System.out.print(newMessage);
if (exception != null) exception.printStackTrace(System.out);
}
}
Changed another block of code in HomeAction.java
to:
if(cosn!= null && cosn.matches("[0-9a-zA-Z_]+")) {
...
}
But that didn't help. How do I validate/sanitize/encode Line 69. Any help is much appreciated.
Thanks