I'm working on an AngularJS webapp with a Laravel backend.

I want to enable CSRF protection with cross-domain requests. Is it possible?

$http reference in "Cross Site Request Forgery" says "The header will not be set for cross-domain requests"

Looking the Developer Tools logs I see that after the $http.post call the preflight request is sent (OPTION verb) and it has the XSRF-TOKEN cookies set, but the POST request has no cookies so I can't do:

$http.defaults.headers.post['X-CSRFToken'] = $cookies['XSRF-TOKEN'];

Any idea?

UPDATE:

@zeroflagL: I tried with

$http.defaults.headers.common.xsrfCookieName = 'XSRF-TOKEN';
$http.defaults.headers.common.xsrfHeaderName = 'X-XSRF-TOKEN';

And now in the Request headers of the POST I have:

xsrfCookieName:XSRF-TOKEN
xsrfHeaderName:X-XSRF-TOKEN

But the CSRF check is not passed (TokenMismatchException on the server). I suppose that in the Request headers there should be the XSRF-TOKEN to work...

share|improve this question
1  
Did you set xsrfHeaderName and xsrfCookieName as said in the documentation? – zeroflagL Nov 12 '15 at 16:53
    
@zeroflagL: I tried without success, updated my post – Mat Nov 12 '15 at 20:29
    
Remove headers.common. It's just $http.defaults.xsrf.... – zeroflagL Nov 12 '15 at 21:07
    
It should be correct with $http.defaults.headers.common.xsrf..., if I use your form nothing is set in the POST request headers. BTW this doesn't resolve the problem – Mat Nov 13 '15 at 7:39
1  
Example: You have a website http://myweb.com. The user is logged in. The user opens the site http://evil.com in another tab. That evil site embeds an image tag having the URL http://myweb.com/transferMoney. Because the user is still logged in, the session id is sent and the request seems ok from the servers perspective. If the client runs on the http://anotherweb.com and makes a Cross-Site request to http://myweb.com then XSRF isn't an issue because the request doesn't appear to come from your site anyway. – zeroflagL Nov 13 '15 at 18:15
up vote 0 down vote accepted

As zeroflagL said CSRF protection can't be applied to cross domain requests.

To reply to my question: no, it's not possible.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.