Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/platform-server/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import {RuntimeErrorCode} from './errors';
import {resolveUrl} from './url';

@Injectable()
/**
* @deprecated Use the HttpClient fetch backend (by enabling `withFetch()`) instead.
* XHR support in `@angular/platform-server` is deprecated because the underlying `xhr2`
* library does not safely handle redirects (e.g. it can forward `Authorization` headers
* on cross-origin redirects and is susceptible to denial-of-service (DoS) via redirect loops).
*/
export class ServerXhr implements XhrFactory {
private xhrImpl: typeof import('xhr2') | undefined;

Expand All @@ -29,6 +35,16 @@ export class ServerXhr implements XhrFactory {
// server platform (via shims, etc).
private async ɵloadImpl(): Promise<void> {
if (!this.xhrImpl) {
if (typeof ngDevMode === 'undefined' || ngDevMode) {
console.warn(
'XHR support in `@angular/platform-server` is deprecated and will be removed ' +
'in a future version of Angular. It has known security and performance issues in server ' +
'environments, such as forwarding `Authorization` headers on cross-origin ' +
'redirects and susceptibility to denial-of-service (DoS) via redirect loops. ' +
'Please enable the HttpClient fetch backend instead by using `withFetch()`.',
);
}

const {default: xhr} = await import('xhr2');
this.xhrImpl = xhr;
}
Expand Down
Loading