Repository navigation
fix(@angular/ssr): reject recursive SSR requests before rendering - #34794
Draft
alan-agius4 wants to merge 1 commit into
Draft
alan-agius4 wants to merge 1 commit into
alan-agius4 wants to merge 1 commit into
Conversation
Consume `ɵisSsrRequest` and `ɵSSR_REQUEST_HEADER` from `@angular/platform-server` (introduced in angular/angular#72226) to reject incoming requests that were sent by an Angular application while rendering on the server: - Guard cold-start `ServerRouter.from()` extraction (`!this.router && !this.manifest.routes`) in `AngularServerApp.handle()` to avoid deadlocking on the in-flight route extraction promise. - Reject static redirects in `AngularServerApp.handle()`, locale redirects in `AngularAppEngine.redirectBasedOnAcceptLanguage()`, and server-side rendering in `AngularServerApp.handleRendering()` (including on-demand rendering of prerendered routes when `allowStaticRouteRender` is enabled), while continuing to return `null` for non-Angular routes and serving static prerendered/CSR responses without rendering. - Return `404 Not Found` with `Cache-Control: no-store` (avoiding CDNs like CloudFront caching `400` responses despite `no-store` without triggering 5xx outlier ejection) and log a dev-only warning so loops are observable during development. Closes angular/angular#72223
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: Closes angular/angular#72223
When an application sends an
HttpClientrequest during SSR that lands back on the Angular SSR server (for example, matching a**wildcard route or redirect),@angular/ssrattempts to extract routes or render the page again, which can deadlock on cold-start route extraction or recurse without bound until the Node.js process runs out of memory.What is the new behavior?
Consumes
ɵisSsrRequestandɵSSR_REQUEST_HEADERfrom@angular/platform-server(introduced in angular/angular#72226) to reject incoming recursive SSR requests early:AngularServerApp.handle(), reject requests carryingx-angular-ssr-requestwhen!this.router && !this.manifest.routesbefore callingServerRouter.from()so self-requests during route extraction cannot deadlock on the in-flight extraction promise.redirectTo) inAngularServerApp.handle()and locale redirects inAngularAppEngine.redirectBasedOnAcceptLanguage()whenɵisSsrRequest(request)is true.allowStaticRouteRenderis enabled) inAngularServerApp.handleRendering()before bootstrapping, while still returningnullfor non-Angular routes and serving static prerendered/CSR responses without rendering.404 Not FoundwithCache-Control: no-storeandContent-Type: text/plain(avoiding CDNs like CloudFront caching400responses despiteno-store, without triggering 5xx outlier ejection) and emit a dev-onlyconsole.warncontaining the request URL and header name.Does this PR introduce a breaking change?
Other information
angular/angular-clito exposeɵisSsrRequestandɵSSR_REQUEST_HEADERfrom@angular/platform-server.