Live data from Hacker News

Securing your API: a modern alternative to CSRF tokens

mixmax.com

31–40 of 58 posts

Re: Securing your API: a modern alternative to CSRF tokens

#31
post #26
post #25

Earlier quoted context omitted.

Almost no one ever gets hacked through web app bugs at all, let alone CSRF, so in the end this doesn't really matter. I still wouldn't recommend this as a solution though, since it's been broken repeatedly.

Man oh man I used to think the same but I took infosec training. That taught me little. I held onto the belief hacking a target by website is only for really dumb victims. Then I started reading Bug Bounty reports on HackerOne and BugCrowd and was terrified at people doing account takeovers with CSRF attacks on oft overlooked functionality in no name sites like Twitter or FB. That humbled me real quick. As an aside,…

Are you FB or Twitter or on a similar scale?

Also, bug bounties are not representative of real attacks.

I've written my own share of complicated exploits, but from an actual defense perspective... that's not how people are getting hacked IRL. It's all word macros and sqlmap.

Re: Securing your API: a modern alternative to CSRF tokens

#32
I do this in one of our business' apps. It does strict checking of the Origin and Referer headers when it receives a POST request. We only support modern browsers, and doing this instead of using CSRF tokens feels modern and clean.

I'm paranoid though, so at the last minute, before shipping the first public version of the app, I added a traditional CSRF token check in addition to the Origin/Referer check. I guess it's a layered defense?

Re: Securing your API: a modern alternative to CSRF tokens

#33
post #9

Why make an extremely complicated set up, with many edge cases, all to save yourself from a single token? - 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 tok…

I believe the point of the article is that tokens don't get sent for HEAD or OPTIONS requests, and it's very possible that your API/server are still performing some sort of action on such requests. Or even if not performing a specific action, it still needs to be dealt with and hence is a DDOS vector.

CSRF tokens do not help you in any way against DDOS. CSRF tokens are handed out willingly on essentially any GET request.

Re: Securing your API: a modern alternative to CSRF tokens

#34
post #9

Why make an extremely complicated set up, with many edge cases, all to save yourself from a single token? - 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 tok…

In addition to everything you've mentioned, the double submit cookie approach for csrf defense saves you from storing any state if you don't want to use a backend session.

Re: Securing your API: a modern alternative to CSRF tokens

#35
post #9

Why make an extremely complicated set up, with many edge cases, all to save yourself from a single token? - 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 tok…

Not to be That Guy, but: your sample will reuse the same token over and over until it expires, which is how you get the BREACH attack. In Django 1.10, we switched the CSRF token generation to use a consistent base value, but to combine it in a reversible way with a randomly-generated per-request nonce. CSRF verification then consists of recovering the base value and checking it; this lets you have a longer-lived "tok…

You're wrong. If this is generated every time the page loads you get a new token each time. OR you have to transmit a god awful amount of data on the same page.

When I work for a company that accepts GBs of data over the same TLS connection on a single page, I'll worry about breach and only generating a CSRF token every time a page loads.

Re: Securing your API: a modern alternative to CSRF tokens

#37
post #35

Earlier quoted context omitted.

Not to be That Guy, but: your sample will reuse the same token over and over until it expires, which is how you get the BREACH attack. In Django 1.10, we switched the CSRF token generation to use a consistent base value, but to combine it in a reversible way with a randomly-generated per-request nonce. CSRF verification then consists of recovering the base value and checking it; this lets you have a longer-lived "tok…

You're wrong. If this is generated every time the page loads you get a new token each time. OR you have to transmit a god awful amount of data on the same page. When I work for a company that accepts GBs of data over the same TLS connection on a single page, I'll worry about breach and only generating a CSRF token every time a page loads.

From the sample code provided I was assuming the value would not update on every request (since, if you were changing the expiration timestamp on every request you'd have a bit more work to do than you've shown here -- and either way the sample you've provided isn't a great way to generate the token).

Re: Securing your API: a modern alternative to CSRF tokens

#38
post #30
post #9

Why make an extremely complicated set up, with many edge cases, all to save yourself from a single token? - 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 tok…

Agreed. The solution being proposed with CORS is fragile and complex. Maybe it will be viable in another 5 years' time, with better browser support. But I can't imagine that after reading the article, any dev in his/her right mind will be rushing off to ditch CSRF tokens on production sites. CSRF tokens are taken care of by every web framework out there, anyway. They really should involve zero work to implement. For…

I would like to note that not all frameworks are viable at-scale. We ran into that with Meteor, as it scaled extremely poorly. It didn't implement CSRF tokens, but also didn't use cookies to store auth data, so it didn't much matter.

We only target recent versions of modern browsers, as a consequence of our user base, so we're more able to move to an origin-based solution.

Re: Securing your API: a modern alternative to CSRF tokens

#39

> Firefox will not send the Origin header with any same-origin requests (bug) Am I the only one very surprised to hear this? In 2017? Is there any reason browsers shouldn't just send origin headers along with all requests? Why the exceptions?

Well, it's a bug. It absolutely should send the origin header, but it doesn't ¯\_(ツ)_/¯

Re: Securing your API: a modern alternative to CSRF tokens

#40
post #20

The author admits that this solution won't work for "older" browsers. Which browser versions specifically?

https://caniuse.com/#feat=cors and hit "show all" TL;DR - evergreen browsers, mobile browsers (except for images), IE 11+, and IE 8+ partially supports it

For our specific solution, we also rely on (partial) support for Referrer-Policy: https://caniuse.com/#feat=referrer-policy
Post reply on HN