-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DjangoResource.as_view should call csrf_exempt #21
Comments
Resolution is in #22, but needs tests before it can be merged. |
I'm still not a fan of this, since I even think that csrf_exempt shouldn't be called. The OWASP Cheat Sheet is pretty clear about CSRF, too. It's still a big security issue. |
@c-schmitt I'm confused. For an everyday site leaning on cookies/sessions for web form POSTs, CSRF is essential. But the very nature of an API is that you should be able to access it from other domains/places (think a mobile app) & we're handling authentication explicitly/separately. OWASP's guideline also seem to require performing additional requests in order to get a token. The typical example (in my head) is that of a mobile app. Pre-OWASP, it looks like:
Post-OWASP, I think this looks like:
The post-OWASP process looks way more complex/fallible (not to mention, Restless has no cross-everything way of storing/generating such tokens), for the gain of shoving authentication to a different place. Perhaps I'm incorrect or overlooking something about this & would love to be corrected on where I'm incorrect. |
I must admit confusion on my part as well as I agree with @toastdriven's description of how APIs should work, so after thinking and googling a bit I would like to present my findings, hopefully be less confused and initiate more conversation. These are few links that I found relevant:
It appears that people are of the opinion that APIs, restfull or not, should be protected from CSRF. Initially, my thoughts on the topic were that any API resource should be csrf exempt and therefor my pull request 306c8fb. One of the reasons was similarity with Now, I'm leaning towards agreeing with @c-schmitt. Frameworks should not make the decision if API views should or shouldn't be csrf exempt. There are APIs that use cookie based auth and those are suspectible to CSRF. My conlusion is that if an application is using Django and is configured to be protected against CSRF then framework such as I see two possible ways this can be resolved:
I still want to write those tests for #22 and plan to do so in the following weeks as those will be useful in any case this goes forward. I would definitely want to continue this discussion in the meantime and hear your opinions. |
DjangoResource
as_list
andas_detail
callcsrf_exempt
on theirsuper
, butas_view
is not overriden any custom endpoint method is protected with Django CSRF (and it shouldn't be).The text was updated successfully, but these errors were encountered: