Spring CSRF unrestricted RequestMapping

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: java-security/spring-csrf-requestmapping

Language: Java

Severity: Warning

Category: Security

CWE: 352

Description

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 GETHEADTRACE, and OPTIONS.

For this reason, requests or routes with RequestMapping, and not narrowing the mapping to the HTTP request methods POSTPUTDELETE, or PATCH, makes them vulnerable to CSRF attacks.

Learn More

Non-Compliant Code Examples

@Controller
public class UnsafeController {

    @RequestMapping("/path")
    public void writeData() {
        // State-changing operations performed within this method.
    }
}

Compliant Code Examples

@Controller
public class SafeController {

    /**
     * For methods without side-effects use @GetMapping.
     */
    @GetMapping("/path")
    public String readData() {
        // No state-changing operations performed within this method.
        return "";
    }

    /**
     * For state-changing methods use either @PostMapping, @PutMapping, @DeleteMapping, or @PatchMapping.
     */
    @PostMapping("/path")
    public void writeData() {
        // State-changing operations performed within this method.
    }
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: mervebolat/span-id-preprocessing