Recently I came across an application which was preventing crsf attacks using a unique non-traditional approach. In traditional approach the csrf is thwarted by embedding unique random tokens, called nonce, in each sensitive page. But this application, which was making ajax calls and used jQuery, was creating a header to identify the valid and invalid requests altogether. The idea is to generate a custom header, x-session-token in this case, with every request which is considered sensitive and includes any sort of transaction. For example:
xhr.setRequestHeader('x-session-token', csrf_token)
At the server level, server checks for this header if found request is fulfilled, otherwise rejected.
We need to use xhr calls for making use of this technique, not useful in regular POST and GET requests. Since, I was not aware of this kind of countermeasures, probably, since most of the applications I did were using standard requests. So, I searched a bit and found even Google also uses this approach predominately. However, it seems not be best approach, where custom headers can also be exploited, but certainly, it raises the bar and simpler approach. And a new thing for my knowledge also!
Reference: https://nealpoole.com/blog/2010/11/preventing-csrf-attacks-with-ajax-and-http-headers/#comment-1675
Comments