← Java / Spring · Contents

JAVA-020 / Beginner

Disabling Spring Security CSRF (csrf().disable())

A01:2021 Broken Access Control · CWE-352 CSRF

Why is this a problem?

Cross-site requests pass through session-cookie-based APIs.

How to fix it

java
http.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()));
// Disable only for purely token-based (Bearer) APIs and document the reason

Further reading