0

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...

8
  • 1
    Did you set xsrfHeaderName and xsrfCookieName as said in the documentation? Commented Nov 12, 2015 at 16:53
  • @zeroflagL: I tried without success, updated my post Commented Nov 12, 2015 at 20:29
  • Remove headers.common. It's just $http.defaults.xsrf.... Commented Nov 12, 2015 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 Commented Nov 13, 2015 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. Commented Nov 13, 2015 at 18:15

1 Answer 1

1

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.