fix(xsrf): overwrite already set xsrf header
This commit is contained in:
parent
178fb79b5c
commit
b4265e0685
|
@ -187,7 +187,7 @@ export class CookieXSRFStrategy implements XSRFStrategy {
|
||||||
|
|
||||||
configureRequest(req: Request) {
|
configureRequest(req: Request) {
|
||||||
let xsrfToken = __platform_browser_private__.getDOM().getCookie(this._cookieName);
|
let xsrfToken = __platform_browser_private__.getDOM().getCookie(this._cookieName);
|
||||||
if (xsrfToken && !req.headers.has(this._headerName)) {
|
if (xsrfToken) {
|
||||||
req.headers.set(this._headerName, xsrfToken);
|
req.headers.set(this._headerName, xsrfToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,11 +124,11 @@ export function main() {
|
||||||
backend.createConnection(sampleRequest);
|
backend.createConnection(sampleRequest);
|
||||||
expect(sampleRequest.headers.get('X-XSRF-TOKEN')).toBe('magic XSRF value');
|
expect(sampleRequest.headers.get('X-XSRF-TOKEN')).toBe('magic XSRF value');
|
||||||
});
|
});
|
||||||
it('respects existing headers', () => {
|
it('should allow overwriting of existing headers', () => {
|
||||||
getDOM().setCookie('XSRF-TOKEN', 'magic XSRF value');
|
getDOM().setCookie('XSRF-TOKEN', 'magic XSRF value');
|
||||||
sampleRequest.headers.set('X-XSRF-TOKEN', 'already set');
|
sampleRequest.headers.set('X-XSRF-TOKEN', 'already set');
|
||||||
backend.createConnection(sampleRequest);
|
backend.createConnection(sampleRequest);
|
||||||
expect(sampleRequest.headers.get('X-XSRF-TOKEN')).toBe('already set');
|
expect(sampleRequest.headers.get('X-XSRF-TOKEN')).toBe('magic XSRF value');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('configuration', () => {
|
describe('configuration', () => {
|
||||||
|
|
Loading…
Reference in New Issue