advancedCSRF: Cross-Site Request Forgery

How does a CSRF token actually stop a forged request?

The server issues a unique, hard-to-guess token per session/request and requires it to be present (matching) on every state-changing request. A malicious third-party page cannot read this token (due to Same-Origin Policy preventing it from reading responses/cookies belonging to a different origin), so any forged request it sends is missing the token or has an invalid one, and Spring Security's CsrfFilter rejects it with HTTP 403.

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full Spring Ecosystem Mastery library.

How does a CSRF token actually stop a forged request?

Next Step

Continue to Why does CookieCsrfTokenRepository use withHttpOnlyFalse(), when HttpOnly is usually a security best practice for cookies?← Back to all Spring Security questions