advancedCSRF: Cross-Site Request Forgery

Why does CookieCsrfTokenRepository use withHttpOnlyFalse(), when HttpOnly is usually a security best practice for cookies?

The CSRF token's protection model depends on your OWN frontend JavaScript being able to read the token value from the cookie and echo it back as a request header — this only works if JavaScript CAN read it. Security still holds because a DIFFERENT (attacker) origin cannot read your domain's cookies at all, due to Same-Origin Policy — HttpOnly would only additionally protect against XSS reading it, which is a different threat model from CSRF.

This is a Pro chapter

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

Why does CookieCsrfTokenRepository use withHttpOnlyFalse(), when HttpOnly is usually a security best practice for cookies?

Next Step

Continue to Why doesn't Spring Security's default CSRF protection cover GET requests?← Back to all Spring Security questions