如何在 SAST Checkmarx 之后解决 API 控制器中的 XSRF 跨站请求伪造 (CSRF)

问题描述

我已经使用 Checkmarx 工具完成了我的项目 java spring boot 的扫描。 该工具发现了大约 23 个中等严重性的 XSRF 出现。

发现的问题已在 @RequestBody List<String> lineups 上的 Rest API 方法 POST 上标记

附上描述结果的截图:

enter image description here

    @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;

    }

是否有解决问题的示例修复程序?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)