<< Which Conference? | Home | CSRF Pharming >>

CSRF Protection

It occurred to me that there is another way of providing protection against CSRF attacks, in addition to the ones already mentioned on Wikipedia.

There are several ways to forge a request in a CSRF attack: iframe, script tag, image tag, scripted window.open() etc. As far as I know XHR is not one of these, because cross-domain rules kick in before the request is sent and not when the reply is read.

Both iframe and XHR will allow you to construct POST requests, the other attack mechanisms are restricted to GET only. With the iframe method, you use some DOM scripting to create a form that points to an iframe. This implies that only form-formatted data can be sent over an iframe POST request.

So in the Ajax world, it might be possible to have a CSRF-safe application that works simply by insisting on POST, and denying anything that is application/x-www-form-urlencoded. Clearly this technique won't work for non Ajax requests because it requires the browser to use XHR.

Obviously this is a fairly advanced technique, but it might be useful for anyone writing an Ajax library like for example DWR. I should see if I can't find a DWR tech-lead around here somewhere.

Anyone any clues on whether this might help as part of a defence in depth policy?



Re: CSRF Protection

Hey Joe, couldn't find a way to contact you directly, so I hope you get notified on comments even on old posts. I'm currently doing security research for my current project, starting with the OWASP Top 10.. I'm stuck on the advice for protection against CSRF attacks. OWASP says "[...] tokens can be unique to that particular function or page for that user, or simply unique to the overall session". The latter would be easier to implement, especially in regards to Ajax, as I wouldn't have to send a new token with every Ajax response, to be used for the next request. From my understanding, the unique token would be compromosed when faced with an XSS flaw, so the scope wouldn't matter much anyway. I couldn't find any arguments or examples for a token more focused then the user session. Do you have any advice or further material for that issue? Thanks Jörn

Re: CSRF Protection

PS: It would be nice of your comment system to regard new lines as linebreaks...

Add a comment Send a TrackBack