Securing your API: a modern alternative to CSRF tokens
1–10 of 58 posts
Re: Securing your API: a modern alternative to CSRF tokens
#2And of course it would be better if browsers would not make cross-origin requests unless permitted by server.
Re: Securing your API: a modern alternative to CSRF tokens
#3Also, I really don't get the relevance of the refutation of "Use only JSON APIs" - it's a fixed bug that seemingly only impacted Chrome anyway? The second point is that preflights are expensive, which might have some weight - but e.g. Twitch seem to cope okay with these preflights and I think a lot of browsers do cache them for a short period of time now anyway.
I'll be sticking to CSRF tokens plus SameSite cookies (for where the browser supports them). The only issue I can see with SameSite is that JS can still send requests (with no credentials), but I'm not convinced this is a credible DoS vector.
Re: Securing your API: a modern alternative to CSRF tokens
#4They tried to propose a simple modern solution but after reading the article it does not look simple and works much worse than traditional approach with tokens. And of course it would be better if browsers would not make cross-origin requests unless permitted by server.
Re: Securing your API: a modern alternative to CSRF tokens
#5However there's been enough referer spoofing browser bugs lately that I'd rather have the extra safety (and complexity) of CSRF tokens. Just 3 months ago Edge had (another) referer spoofing bug: https://www.brokenbrowser.com/referer-spoofing-patch-bypass/
Re: Securing your API: a modern alternative to CSRF tokens
#6Re: Securing your API: a modern alternative to CSRF tokens
#7I used to prefer the origin/referer approach to blocking CSRF because it can be done upstream of the application server (or in a middleware), transparent to developers who often get these things wrong. However there's been enough referer spoofing browser bugs lately that I'd rather have the extra safety (and complexity) of CSRF tokens. Just 3 months ago Edge had (another) referer spoofing bug: https://www.brokenbrows…
There are plenty of middleware-like solutions that can add solutions automatically too. And if you fail closed, you will always notice in testing and can add tokens where they are missing.
Re: Securing your API: a modern alternative to CSRF tokens
#8Re: Securing your API: a modern alternative to CSRF tokens
#9 - Privacy extensions often times block referrer headers.
- POST requests are usually necessary.
- Open redirects are common bugs, and getting your website to initiate one can be a problem.
- Disabling CORS also relies on you killing crossdomain.xml, which you might overlook.
Instead you can just roll out CSRF tokens.Having rolled them out myself many times. You probably want to use a library if you aren't a cryptographer or security person:
expiration_time_of_1_day || hmac_sha256( secret_key, { expiration_time_of_1_day, user_id })
I've seen other people mention SameSite cookies, but we aren't near a time when browsers all support them. Don't get fancy preventing CSRF. It's a stupid bug.Re: Securing your API: a modern alternative to CSRF tokens
#10Thoughtful article!