我在下面得到了这个错误。使用ResponseWriter时。我该如何解决?
try {
unifiedResponse = testController.updateData(testRequest);
} catch (RestClientResponseException e) {
try {
PrintWriter writer = response.getWriter();
response.setContentType(MediaType.TEXT_PLAIN);
response.setStatus(e.getRawStatusCode());
writer.print(e.getResponseBodyAsString());
} catch (IOException ex) {
throw new ServiceException("Cannot get update Password error response body", ex);
}
}
错误:
This use of java/io/PrintWriter.write(Ljava/lang/String;)V could be vulnerable to XSS
我的输出是JSON,HTMLEscape和OWASP创建了错误的格式,这是我需要的。
{
"message": "Here is a test message"
}
OWASP输出:
{"message":"Here is a test message (e.g. !@#$)."}
SonarQube规则:
我尝试了SonarQube的官方解决方案,但仍然出现错误https://rules.sonarsource.com/java/RSPEC-5131/