question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider dropping explicit CSRF protection entirely?

See original GitHub issue

https://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:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
simonwcommented, Jul 1, 2020

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

0reactions
simonwcommented, Sep 15, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found