[Solved]-CSRF Token in Django and iOS


You’re right: if you don’t use cookies to manage your sessions, you don’t need CSRF protection. CSRF works because session cookies are automatically attached to the request; access tokens are not.

I personally found this article very useful. It is definitely worth reading, and would probably answer a lot of your questions.

As for tastypie: it allows SessionAuthentication. If you allow session authentication in tastypie, I suggest you look into a way to protect your users against CSRF. For other authentication schemes this doesn’t seem necessary. As far as I know, Dmitry is right about tastypie disabling CSRF by default, which means it is strange that you get that 403 Error. Perhaps there is something else going on. Try wrapping the view in @csrf_exempt.

As for CSRF tokens, they are also called session independent nonces. They are meant to be permanent, but you probably know that is impossible for cookies. Anyway, this means that CSRF cookies persist through sessions.


You’re right, CSRF does not make much sense in this case, because its purpose is to protect users from data tampering in a browser.

I believe that Tastypie disables CSRF on its views by default.

Leave a comment