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
Mechanism for skipping CSRF checks on API posts #835
Comments
Tweeted about this here: https://twitter.com/simonw/status/1273655053170077701 |
I think there are a couple of steps to this one. The nature of CSRF is that it's about hijacking existing authentication credentials. If your Datasette site runs without any authentication plugins at all CSRF protection isn't actually useful. Some POST endpoints should be able to opt-out of CSRF protection entirely. A writable canned query that accepts anonymous poll submissions for example might determine that CSRF is not needed. If a plugin adds This means I need two new mechanisms:
|
Here's the Rails pattern for this: https://gist.github.com/maxivak/a25957942b6c21a41acd |
The only way I can think of for a view to opt-out of CSRF protection is for them to be able to reconfigure the |
Since Lines 877 to 888 in d2aef9f
|
I wonder if it's safe to generically say "Don't do CSRF protection on any request that includes a |
|
Idea: a mechanism where the |
Useful tip from Carlton Gibson: https://twitter.com/carltongibson/status/1273680590672453632
|
So maybe one really easy fix here is to disable CSRF checks entirely for any request that doesn't have any cookies? Also suggested here: https://twitter.com/mrkurt/status/1273682965168603137 |
Problem there is Login CSRF attacks: https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#login-csrf - I still want to perform CSRF checks on login forms, even though the user may not yet have any cookies. Maybe I can turn off CSRF checks for cookie-free requests but allow login forms to specifically opt back in to CSRF protection? |
Skipping CSRF on |
I'm going to add some tests for this. |
simonw commentedJun 11, 2020
While experimenting with https://github.com/simonw/datasette-auth-tokens I realized it's not currently possible to build API client programs that POST to Datasette because there's no mechanism for them to skip the CSRF checks added in #798.
The text was updated successfully, but these errors were encountered: