我在我的存储库上运行了 CheckMarx Scan,它给出了很多潜在的反射 XSS 攻击结果。这是我的控制器的代码:
@PutMapping("/calculate")
public UpdatedResponse calculateModel(
@RequestBody ModelDocument modelDocument, @RequestParam String clientFirstName,
@PathVariable String clientId, @PathVariable String clientLastName
) {
// Sanitize the parameters
modelDocument = checkForCSS(modelDocument); // NOT ACCEPTING THIS
clientId = StringEscapeUtils.escapeHtml4(clientId);
clientFirstName = StringEscapeUtils.escapeHtml4(clientFirstName);
clientLastName = StringEscapeUtils.escapeHtml4(clientLastName);
.....
}
虽然我能够解决警告,clientId, clientFirstName and clientLastName
因为它们都是字符串变量。但是我该怎么做,modelDocument
因为它本身就是一个用户定义的变量,并且在其中定义了各种字符串、映射等。
方法 checkForCSS 定义如下,但扫描无法识别:
public static <T> T checkForCSS(T t) {
Gson gson = new GsonBuilder().serializeSpecialFloatingPointValues().create();
String agendaModelStr = sanitize(gson.toJson(t));
return gson.fromJson(agendaModelStr, (Type) t.getClass());
}
public static String sanitize(String string) {
return Jsoup.clean(string, "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false));
任何帮助,将不胜感激。谢谢!