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을 만듭니다
무료 IDE 플러그인을 사용하거나 CI 파이프라인에 Code Security 검사를 추가합니다