Replies: 3 comments 3 replies
|
@way-dave - CSRF is not disabled by default - it's enabled automaticaly only for authentication methods that can have this voulnorability (like Cookie based / Session based auth) All the other methods (basically any that do not store state in browsers are safe) |
|
The cookie-based authentication methods are not enabled by default, so to me, that means CSRF is disabled by default. 🤷 Either way, here's what happened in an app I maintain:
This was quite a scary side-effect to discover. Worse, it's not really obvious how to fix this. |
what I mean here - cookie based - means you authentication is inherited from APIKeyCookie class YourCustomAuthentication(APIKeyCookie):
def authenticate(self, request, key):
your logicthat way OpenAPI spec will reflect the reality of your logic and you will have csrf validation |
Uh oh!
There was an error while loading. Please reload this page.
Disabling CSRF protection in APIs by default seems extremely dangerous to me, since you have to read the documentation to figure it out. In general I'd much prefer security features defaulted to on rather than off. Particularly given users familiar with Django's built-in CSRF protection would not assume a framework-wide disabling of that protection!
But that would be a breaking change for
ninja, so instead, it would be great to have acsrf_exemptparameter forNinjaAPIthat defaults toTrue(for backwards compatibility). This would directly correspond to thecsrf_exemptflag that is currently set on the view wrappers byninja, allowing developers to re-enable the standard Django CSRF protection.Otherwise, there's no clear way to re-enable CSRF protection without adding a cookie-based auth handler, which isn't appropriate for app apps.
All reactions