Skip to content

Question: Why is CSRF protection needed when I use XMLHttpRequest for all my API calls? #1006

Answered by jwag956
abceleung asked this question in Q&A
Discussion options

You must be logged in to vote

These are always good questions - and things do change (slowly). First - how data is sent - forms versus JSON doesn't matter at all. It is all about how authorization information is sent. In the (common) case of authorization being sent as part of a cookie - your application is susceptible for CSRF and MUST have protection. If sending authorization via a header only (no cookies) then I agree that CSRF can't happen.

The thing to remember is that the browser will send the cookie every time a request is made to your site - regardless of which 'tab' makes the request. Only POSTs are an issue since GETs are limited by browsers same-origin policy (https://security.stackexchange.com/questions/11…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@abceleung
Comment options

Answer selected by abceleung
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants