7 ms·
I'm not familiar with CSRF so had to look this up: [Cross Site Request Forgery] vulnerabilities occur when a website allows an authenticated user to perform a
by adolph 15y ago
I'm not familiar with CSRF so had to look this up:
[Cross Site Request Forgery] vulnerabilities occur when a website allows an authenticated user to perform a sensitive action but does not verify that the user herself is invoking that action. The key to understanding CSRF attacks is to recognize that websites typically don't verify that a request came from an authorized user. Instead they verify only that the request came from the browser of an authorized user. Because browsers run code sent by multiple sites, there is a danger that one site will (unbeknownst to the user) send a request to a second site, and the second site will mistakenly think that the user authorized the request.
From: http://freedom-to-tinker.com/blog/wzeller/popular-websites-vulnerable-cross-site-request-forgery-attacks http://freedom-to-tinker.com/blog/wzeller/popular-websites-v...
Via: http://www.codinghorror.com/blog/2008/10/preventing-csrf-and-xsrf-attacks.html http://www.codinghorror.com/blog/2008/10/preventing-csrf-and...
- cheez 15y agoI hope you're not a web programmer. I'm not a web programmer and I knew that.
- yoyar 15y agoAnd the award for most pompous, unnecessary, and conceited response goes to... cheez!
- espeed 15y agoA few days ago I asked, "Ask HN: Best Approaches to Prevent Session Hijacking?" (http://news.ycombinator.com/item?id=2663293 http://news.ycombinator.com/item?id=2663293) and presented a technique I'm experimenting with that uses session timestamps as tokens to validate that each request is authentic and an attacker hasn't stolen the session key. It works by updating the token (timestamp) on the server and in the cookie on each request and they both have to match on the next request. A short buffer (say 30 seconds) is permitted to avoid false positives from click-happy users on slow/flaky connections. Has anyone used this technique in production?
- sonnym 15y agoHow do you mitigate problems with a user opening multiple tabs over a span of time, and attempting to submit the first one opened? I believe the best practice is to provide the user's session id in their cookie and provide that with the requests via javascript or even at the time of page rendering. Since a third party (untrusted domain) cannot access information from your cookie, they also cannot form a valid request. This method is called double submitting cookies. See: https://secure.wikimedia.org/wikipedia/en/wiki/Cross-site_request_forgery#Prevention https://secure.wikimedia.org/wikipedia/en/wiki/Cross-site_re...
- espeed 15y agoA session is shared between multiple browser tabs so this shouldn't be a problem. If the user opens a new tab/browser in incognito mode, then the browser will ask them to login in again b/c it can't read their session to authenticate their identity, and then when they login they will have two separate sessions going, each with a unique token/timestamp so multiple sessions isn't a problem either.
- sonnym 15y agoMy bad, I thought the timestamp was being inserted into a form ala Rails' authenticity_token method in a way that would allow it to go stale if a new request was submitted in a new tab. Although this makes sense, I feel it is not as safe as double submitting cookies, which effectively creates pseudo-random requests, but should still be safe enough in practice.
- alanning 15y agoHaacked has a step-by-step description of how this attack works: http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-js... The Microsoft asp.net web stack avoids this by automatically wrapping json responses with an object "{d:...}". The comments describe this as only affecting FF2.0 although testing was informal. (You should, of course, still protect your services.)
- arethuza 15y agoI think it's just the ASP.Net AJAX Toolkit not plain ASP.Net or ASP.Net MVC.
- alanning 15y agoThanks, I should have clarified. Here is the breakdown according to Phil's post linked below: ASP.NET ASMX Web Services, WCF Web Services, and the now-defunct ASP.NET AJAX automatically wrap with {'d':...}. ASP.NET MVC does not. Phil explains that the reason there is a difference is that with MVC there is no common client library that automatically strips the {'d':...} wrapper. So they felt it would be too confusing for users. http://haacked.com/archive/2009/06/25/json-hijacking.aspx http://haacked.com/archive/2009/06/25/json-hijacking.aspx That was an old article so maybe they have changed the default behavior since then. In any case, you can manually wrap the response with {'d':...}.
- mustpax 15y agoThat wouldn't work, you can override the Object constructor in JavaScript as well. You have to prepend something like `while(1);` to the JSON responses you're returning.
- alanning 15y agoI can see why you would think that but it does work because a script that just contains a JSON object is not a valid JavaScript file. The browser will give an error. Whereas a script that just contains a JSON array is valid.