Consider dropping explicit CSRF protection entirely?
See original GitHub issuehttps://scotthelme.co.uk/csrf-is-dead/ from Feb 2017 has background here. The SameSite=lax
cookie property effectively eliminates CSRF in modern browsers. https://caniuse.com/#search=SameSite shows 92.13% global support for it.
Datasette already uses SameSite=lax
when it sets cookies by default: https://github.com/simonw/datasette/blob/af350ba4571b8e3f9708c40f2ddb48fea7ac1084/datasette/utils/asgi.py#L327-L341
A few options then. I could ditch CSRF protection entirely. I could make it optional - turn it off by default, but let users who care about that remaining 7.87% of global users opt back into it.
One catch: login CSRF: I don’t see how SameSite=lax
protects against that attack.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Skip CSRF checks if no cookies or if authorization: bearer xxx ...
UNLESS it's to a login form to protect againts login CSRF attacks. ... Consider dropping explicit CSRF protection entirely? simonw/datasette#877.
Read more >The CSRF protection feature does not support dynamically ...
If a critical resource can be defined as an explicit URL, it can be added to the CSRF protection URL list.
Read more >Complete Guide to CSRF/XSRF (Cross-Site Request ...
In this article, we will understand a type of website attack called Cross-Site Request Forgery (CSRF). We will look at the kind of...
Read more >Understanding CSRF Attacks and Locking Down ...
Learn the basics of CSRF attacks and how to prevent them from tricking authenticated users into making harmful requests unintentionally.
Read more >CSRF protection with custom headers (and without ...
The first method involves setting custom headers for each REST request such as X-XSRF-Header. The value of this header does not matter; simply...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Tokens get verified by plugins. So far there’s only one: https://github.com/simonw/datasette-auth-tokens - which has you hard-coding plugins in a configuration file. I have a issue there to add support for database-backed tokens too: https://github.com/simonw/datasette-auth-tokens/issues/1
I’m not going to drop CSRF protection - it’s still needed for older browsers - but I have relaxed the circumstances under which it is applied. It only applies to requests that include cookies for example, so API clients that don’t send cookies don’t need to worry about it.