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.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response