Skip to content

fix(platform-server): prevent recursive SSR HttpClient requests - #72226

Closed
alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:fix/platform-server-ssr-request-loop
Closed

alan-agius4 wants to merge 1 commit into
angular:mainfrom
alan-agius4:fix/platform-server-ssr-request-loop

Conversation

@alan-agius4

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: Related to angular/angular-cli#34789

During SSR, outgoing HttpClient requests (e.g. relative URLs resolved against PlatformLocation with port included) can land back on the SSR server and match a wildcard ** route, triggering unbounded recursive renders until the Node.js process runs out of memory.

What is the new behavior?

  • In SERVER_HTTP_PROVIDERS (packages/platform-server/src/http.ts), mark outgoing HttpClient http:/https: requests targeting the host + port of PlatformLocation (matching default ports 80/443 across schemes for TLS-terminating proxies, normalizing trailing FQDN dots & IPv6, and failing closed on non-HTTP/unparseable URLs) with x-angular-ssr-request: 1. Because this lives in SERVER_HTTP_PROVIDERS, it covers both provideServerRendering() and ServerModule.
  • Export ɵSSR_REQUEST_HEADER and ɵisSsrRequest privately so @angular/ssr can reuse the same header contract and reject recursive SSR requests before rendering.
  • In renderApplication and renderModule, reject incoming REQUEST instances carrying x-angular-ssr-request with RuntimeErrorCode.RECURSIVE_SSR_REQUEST (NG05707) before bootstrapping.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

  • Follow-up in angular/angular-cli (@angular/ssr) will consume ɵisSsrRequest / ɵSSR_REQUEST_HEADER to return a non-cached response before route extraction / rendering.

Mark outgoing `HttpClient` requests sent during server-side rendering that target the host of the page being rendered with an `x-angular-ssr-request: 1` header, and reject incoming `REQUEST` instances carrying this header in `renderApplication` and `renderModule` with `NG05707` before bootstrapping.

Also export `ɵSSR_REQUEST_HEADER` and `ɵisSsrRequest` privately so `@angular/ssr` can reuse the same header contract and reject recursive SSR requests before rendering.

Related to angular/angular-cli#34789
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: server Issues related to server-side rendering

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant