News for hackers. Stuff that matters.
Re:Show HN: This up votes itself by naz on Thursday March 22, 2012 @08:49PM (#3742942)
This is why you shouldn't allow GET for performing actions. An image tag in an article could do the same thing (e: if it didn't check the referrer).
Re:Show HN: This up votes itself by psychotik on Thursday March 22, 2012 @09:13PM (#3743050)
Re:Show HN: This up votes itself by kijin on Thursday March 22, 2012 @09:00PM (#3742987)
It's trivially easy to forge POST requests, too.

What's really needed is a token (nonce) that is tied to the session. That's like CSRF Prevention 101.

Re:Show HN: This up votes itself by Udo on Friday March 23, 2012 @02:21AM (#3743942)
In this specific case merely forging a POST request externally does nothing as the user has to be signed in for this to work. Thus, restricting actions such as voting to POST (and restricting to same-origin) does constitute adequate protection if there is no XSS vulnerability on the site.
Re:Show HN: This up votes itself by simonw on Friday March 23, 2012 @04:44AM (#3744206)
But if the user IS signed in (and if someone arrives at your site from a link on Hacker News there's a very good chance they will be signed in) a POST forged from your site can affect their session. Read up on CSRF - it's a very different vulnerability from XSS (though having an XSS vulnerability will make any CSRF protection you have in place null and void).

http://en.wikipedia.org/wiki/CSRF

Re:Show HN: This up votes itself by Udo on Friday March 23, 2012 @05:54AM (#3744339)
Don't be so condescending, you didn't read my entire post. To quote myself:

  > POST (and restricting to same-origin)
I still don't think it's possible to forge the referer header on an uncompromised browser.
Re:Show HN: This up votes itself by sp332 on Friday March 23, 2012 @05:12PM (#3747325)
Would restricting to same-origin break http://hackerne.ws?
Re:Show HN: This up votes itself by rabidsnail on Thursday March 22, 2012 @09:43PM (#3743172)
Or xhr with custom header, if you don't want to have to keep track of state.
Re:Show HN: This up votes itself by kijin on Thursday March 22, 2012 @10:53PM (#3743402)
So that anyone who has JavaScript disabled will be treated like an attacker? No thanks, HN is one of very few sites nowadays that work fine without JavaScript tricks, and I'd much rather PG kept it that way.
Re:Show HN: This up votes itself by simonster on Thursday March 22, 2012 @10:00PM (#3743230)
A custom header is not sufficient (blame Flash): http://lists.webappsec.org/pipermail/websecurity_lists.webap...
Re:Show HN: This up votes itself by olalonde on Thursday March 22, 2012 @08:51PM (#3742955)
Someone in the other thread pointed out it at least checked the referrer header.
Re:Show HN: This up votes itself by simonw on Thursday March 22, 2012 @08:59PM (#3742983)
That's not a good enough solution - there are decent reasons that a referrer header might be missing (some PC antivirus software strips out referrer headers for example). The only safe way to handle this is with a POST request protected by a CSRF token tied to a cookie.
Re:Show HN: This up votes itself by hashbo on Thursday March 22, 2012 @09:22PM (#3743090)
+1 You can’t trust the Referer header.
Re:Show HN: This up votes itself by jpablo on Thursday March 22, 2012 @09:56PM (#3743222)
GET with randomized ids and checking referrer should be good enough to keeps things simple.
Re:Show HN: This up votes itself by ben0x539 on Thursday March 22, 2012 @09:27PM (#3743100)
Really? I block the referer header so I guess all my upvotes haven't been counted. :(
Re:Show HN: This up votes itself by danielrm26 on Thursday March 22, 2012 @10:08PM (#3743253)
The referer header is also controlled by the client. Anything controlled by the client should be considered tainted.
Re:Show HN: This up votes itself by jbri on Thursday March 22, 2012 @10:26PM (#3743299)
This doesn't really apply when you are trying to verify whether the client actually performed some action.

In a CSRF scenario, the client itself can presumably be "trusted" - A client behaving maliciously can only hurt itself, not any one else. The important thing is to not trust anything that may have been provided by a third party.