Skip to content

Commit 8446e46

Browse files
alan-agius4atscott
authored andcommitted
refactor(platform-server): deprecate ServerXhr
XHR support in `@angular/platform-server` is deprecated because the underlying `xhr2` library does not safely handle redirects. Specifically, it can forward `Authorization` headers on cross-origin redirects (which leaks credentials) and is susceptible to denial-of-service (DoS) via redirect loops. DEPRECATED: XHR support in `@angular/platform-server` is deprecated. Use standard `fetch` APIs instead.
1 parent 547d85a commit 8446e46

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

  • packages/platform-server/src

packages/platform-server/src/http.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ import {RuntimeErrorCode} from './errors';
2020
import {resolveUrl} from './url';
2121

2222
@Injectable()
23+
/**
24+
* @deprecated Use the HttpClient fetch backend instead. Intent to remove in Angular 23.
25+
* XHR support in `@angular/platform-server` is deprecated because the underlying `xhr2`
26+
* library does not safely handle redirects (e.g. it can forward `Authorization` headers
27+
* on cross-origin redirects and is susceptible to denial-of-service (DoS) via redirect loops).
28+
*/
2329
export class ServerXhr implements XhrFactory {
2430
private xhrImpl: typeof import('xhr2') | undefined;
2531

@@ -29,6 +35,16 @@ export class ServerXhr implements XhrFactory {
2935
// server platform (via shims, etc).
3036
private async ɵloadImpl(): Promise<void> {
3137
if (!this.xhrImpl) {
38+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
39+
console.warn(
40+
'XHR support in `@angular/platform-server` is deprecated and will be removed ' +
41+
'in Angular 23. It has known security and performance issues in server ' +
42+
'environments, such as forwarding `Authorization` headers on cross-origin ' +
43+
'redirects and susceptibility to denial-of-service (DoS) via redirect loops. ' +
44+
'Please use the HttpClient fetch backend instead, which is the default since Angular 22.',
45+
);
46+
}
47+
3248
const {default: xhr} = await import('xhr2');
3349
this.xhrImpl = xhr;
3450
}

0 commit comments

Comments
 (0)