Classes that contain methods annotated with RequestMapping are by default mapped to all the HTTP request methods.
Spring Security’s CSRF protection is not enabled by default for the HTTP request methods GET, HEAD, TRACE, and OPTIONS.
For this reason, requests or routes with RequestMapping, and not narrowing the mapping to the HTTP request methods POST, PUT, DELETE, or PATCH, makes them vulnerable to CSRF attacks.
@ControllerpublicclassUnsafeController{@RequestMapping("/path")publicvoidwriteData(){// State-changing operations performed within this method.}}
Compliant Code Examples
@ControllerpublicclassSafeController{/**
* For methods without side-effects use @GetMapping.
*/@GetMapping("/path")publicStringreadData(){// No state-changing operations performed within this method.return"";}/**
* For state-changing methods use either @PostMapping, @PutMapping, @DeleteMapping, or @PatchMapping.
*/@PostMapping("/path")publicvoidwriteData(){// State-changing operations performed within this method.}/**
* You can also use @RequestMapping if you specify a method
*/@RequestMapping(value="/path2",method=RequestMethod.GET)publicStringreadData2(){return"";}}
원활한 통합. Datadog Code Security 사용해 보기
Datadog Code Security
이 규칙을 사용해 Datadog Code Security로 코드 분석해 보기
이 규칙의 사용법
1
2
rulesets:- java-security # Rules to enforce Java security.
리포지토리 루트에서 위의 콘텐츠를 사용해 static-analysis.datadog.yml 생성
Datadog의 무료 IDE Plugins를 사용하거나 Code Security 스캔을 CI 파이프라인에 추가