我已经使用 Checkmarx 工具扫描了我的项目 java spring boot。 该工具发现大约 23 个 XSRF 事件,严重程度为中等。
发现的问题在 @RequestBody List<String> lineups
上的 Rest API 方法 POST 上标记
随附描述结果的屏幕截图:
@RequestMapping(value = "/rules/lineup/{ruleMode}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> getRulesByRuleModeAndLineup(@PathVariable Integer ruleMode,
@RequestBody List<String> lineups) throws Exception {
LOGGER.info("[getRulesByRuleModeAndLineup] ENTER type: " + ruleMode + " lineup: " + lineups);
ResponseEntity<Object> output = null;
List<Rule> rules = new ArrayList<Rule>();
try {
for (String lineup : lineups) {
String lineupSanitized = HtmlUtils.htmlEscape(lineup);
rules.addAll(uiService.getRulesByRuleModeAndLineup(ruleMode, lineupSanitized));
}
output = new ResponseEntity<>(rules, HttpStatus.OK);
} catch (Exception e) {
LOGGER.error(e, e);
output = new ResponseEntity<>("An error occurred: " + e.getMessage() + "'",
HttpStatus.INTERNAL_SERVER_ERROR);
}
return output;
}
是否有解决该问题的示例修复?
最佳答案
您可以选择对该字段进行验证。 这里你有两个选择:
- 使用已经内置的框架,我推荐 spring 为了这: https://docs.spring.io/spring-security/site/docs/3.2.0.CI-SNAPSHOT/reference/html/csrf.html
- 尝试将您想要在 api 上接受的字符串列入白名单,如果您 可以做到这一点。
第二个意味着您有责任使您的列表保持最新。
关于java - 如何在 SAST Checkmarx 之后解决 API Controller 中的 XSRF 跨站请求伪造 (CSRF),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67072503/