advancedCSRF: Cross-Site Request Forgery
Why is CSRF protection typically unnecessary for stateless JWT-based APIs?
CSRF relies on the browser automatically attaching a cookie the attacker's page can't read or control. A JWT sent via a custom Authorization: Bearer header isn't automatically attached by the browser to cross-site requests — the malicious page has no mechanism to make the victim's browser include that header, so there's no forgeable request to protect against, PROVIDED the token isn't ALSO stored in a cookie that gets sent automatically.
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