リポジトリで CheckMarx スキャンを実行したところ、かなり多くの潜在的な Reflected 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));
どんな助けでも大歓迎です。ありがとう!