-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Adding XSRF header when request is NOT same origin, but is TRUSTED origin (subdomain) #7862
Comments
Interesting. Since subdomains don't have access to cookies unless the cookie is specified with '.'-prefixed domain ( Now if you do use dot prefixed domain for auth cookie, and you use cookie based authentication for your api then you do need the xsrf token in the url to protect the app. that however means opting into the pre-flight requests for CORS, which complicates things quite a bit. maybe a generic solution would be to provide a way to force XSRF token to be sent for CORS requests regardless of the same origin check. That way if for some reason you want to send XSRF token to your subdomain or totally unrelated domain and you are ready to deal with preflight CORS requests you have an option to do that. @chirayuk what's your take? |
@IgorMinar a flag to override the same origin check for XSRF tokens would indeed be nice. |
Correct me if I'm wrong, but here's how I understand things: An app in running on The XSRF token can be used by the server on So, the moment we start sending XSRF tokens to any domain othar than the one we are currently running from, we are in the mercy of anyone controlling that domain. Taking that into account, allowing people to disable the "same origin" check, sounds like a really bad idea - you could as well drop XSRF altogether. There is obviously no problem if the same person controls both A better option might be allowing users to whitelist specific domains for sending the XSRF token or allowing people to specify that subdomains should also receive the XSRF token and leave it up to them to make sure that their app will always be deployed on domains, where they have full control over subdomains. Thoughts? |
the white-list option sounds the best to me. |
Well this is old... +1 for whitelisting. I guess that's what I meant by "trusted" domains. |
Normally, the XSRF token will not be set for cross-origin requests. With this commit, it is possible to whitelist additional origin, so that requests to these origins will include the XSRF token. Fixes angular#7862
Normally, the XSRF token will not be set for cross-origin requests. With this commit, it is possible to whitelist additional origins, so that requests to these origins will include the XSRF token header. Fixes angular#7862
Normally, the XSRF token will not be set for cross-origin requests. With this commit, it is possible to whitelist additional origins, so that requests to these origins will include the XSRF token header. Fixes angular#7862
Yep. Checking for same origin is very strange behavior, imho. |
There is a PR (#14890) for making this configurable, but it hasn't gotten much traction (yet) 😁 |
Normally, the XSRF token will not be set for cross-origin requests. With this commit, it is possible to whitelist additional origins, so that requests to these origins will include the XSRF token header. Fixes angular#7862
Normally, the XSRF token will not be set for cross-origin requests. With this commit, it is possible to whitelist additional origins, so that requests to these origins will include the XSRF token header. Fixes angular#7862
Normally, the XSRF token will not be set for cross-origin requests. With this commit, it is possible to whitelist additional origins, so that requests to these origins will include the XSRF token header. Fixes angular#7862
Normally, the XSRF token will not be set for cross-origin requests. With this commit, it is possible to whitelist additional origins, so that requests to these origins will include the XSRF token header. Fixes angular#7862
@gkalpak is there a way of doing this in the current implementation of Angular? This is the exact issue I'm having. HttpXsrfTokenExtractor.getToken() always returns null because my rest api that is providing the cookie is cross-origin. |
No idea 😁 |
Normally, the XSRF token will not be set for cross-origin requests. With this commit, it is possible to whitelist additional origins, so that requests to these origins will include the XSRF token header. Fixes #7862
So this may (probably) just be that I'm not understanding XSRF prevention correctly, so feel free to tell me I'm an idiot. But currently in the code (
angular.js/src/ng/http.js
Lines 883 to 893 in dd1d189
urlIsSameOrigin(config.url)
. If it's not same origin, angular does not add the XSRF header token (X-XSRF-TOKEN
).Now, that's all good. Except that I'm requesting
api.example.com
fromexample.com
, which fails the same origin check. Should this be allowed? Or does that somehow completely break the XSRF prevention?The text was updated successfully, but these errors were encountered: