PDA

View Full Version : Spring Security CSRF meta tag Dom Selection



whodat
15 Apr 2015, 12:29 PM
I'm using Spring Security in my application and our POST calls need append a CSRF token to all request headers which are posted to our server side.

Looking at Spring Security blog, I've found the following solution in jquery.


var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");


The meta tags in my single page app are:


<meta name="_csrf_parameter" content="_csrf" />
<meta name="_csrf_header" content="X-CSRF-TOKEN" />
<meta name="_csrf" content="......." />


How can I achieve the selection like what was done in jquery. I'll grab the values and add them to my overrides file so that each request has the token added in the header.

I've tried the following but getting "Error parsing selector. Parsing failed at "['_csrf']"

var value = Ext.dom.Query.select("meta['_csrf']");

Any help would be greatly appreciated

skirtle
15 Apr 2015, 4:19 PM
It'd be the same as the selector for jQuery wouldn't it? You've dropped the 'name=' part in your Ext version.

whodat
16 Apr 2015, 4:02 AM
It'd be the same as the selector for jQuery wouldn't it? You've dropped the 'name=' part in your Ext version.

Hi Skirtle,

Thanks for replying. I was trying different combinations yesterday. Maybe it was just a long day. Thanks I-|


Ext.dom.Query.select("meta[name='_csrf']");