Django REST Framework does not check CSRF token on endpoints not requiring authentication #7389
Labels
bug
Behavior is wrong or broken
DEV: backend
Python, databases, networking, filesystem...
P1 - important
Priority: High impact on UX
Milestone
Observed behavior
It appears that DRF accomplishes its CSRF-checking as part of the
SessionAuthentication
authentication class:https://stackoverflow.com/questions/49275069/csrf-is-only-checked-when-authenticated-in-drf
This means that endpoints that allow anonymous POST requests aren't CSRF-protected. This generally isn't a huge deal, since the point of CSRF protection is to prevent someone from making you do an action as a particular user. But:
Expected behavior
On all endpoints that are intended to be accessed solely from the browser, we should/could be more strongly enforcing CSRF protections.
User-facing consequences
The main (only?) place this is likely to come into play at the moment is the login endpoint. Worst impact is that by visiting a 3rd party site, it could trigger your browser to log into a Kolibri site as an arbitrary user (for which it knows the credentials). If you then visited the Kolibri site, before the session timed out, any activity would be logged to the attacker's account and could later be inspected.
Given our short session timeouts, the hoops to jump through to accomplish this, and the moderately low impact (doesn't give access to user's account, just temporarily logs them in as another user), this doesn't seem like a blocker for 0.14, but would be good to do a broader audit and address in the future. We'll need to be aware that there could be unknown 3rd-party integrations with Kolibri that make use of our login endpoint and don't bother setting CSRF headers (since it works without), so this could also require some of those integrations. But given the login endpoint isn't a "public" endpoint, we haven't committed to forwards-compatibility.
Steps to reproduce
Try:
and you should see a successfully created session's JSON blob.
The text was updated successfully, but these errors were encountered: