Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Adding XSRF header when request is NOT same origin, but is TRUSTED origin (subdomain) #7862

Closed
@brettstack

Description

@brettstack

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

if (isUndefined(cachedResp)) {
var xsrfValue = urlIsSameOrigin(config.url)
? $browser.cookies()[config.xsrfCookieName || defaults.xsrfCookieName]
: undefined;
if (xsrfValue) {
reqHeaders[(config.xsrfHeaderName || defaults.xsrfHeaderName)] = xsrfValue;
}
$httpBackend(config.method, url, reqData, done, reqHeaders, config.timeout,
config.withCredentials, config.responseType);
}
), angular is checking if the requested URL is same origin with 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 from example.com, which fails the same origin check. Should this be allowed? Or does that somehow completely break the XSRF prevention?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions