Skip to content

feat(@angular/ssr): support the standard Forwarded header#33406

Merged
alan-agius4 merged 2 commits into
angular:mainfrom
alan-agius4:feat/forwarded-header
Jun 23, 2026
Merged

feat(@angular/ssr): support the standard Forwarded header#33406
alan-agius4 merged 2 commits into
angular:mainfrom
alan-agius4:feat/forwarded-header

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

This commit adds support for the standard RFC 7239 Forwarded header in the Angular SSR request parsing and validation layers.

Previously, only non-standard x-forwarded-* headers were supported for resolving proxy-forwarded protocols, hosts, and ports. With this change:

  • A new parseForwardedHeader utility is added to parse standard Forwarded header parameters (such as host and proto), correctly handling quoted values and escaped characters.
  • In createRequestUrl, if the Forwarded header is trusted (via trustProxyHeaders configuration), its host and proto parameters are extracted and take precedence over corresponding x-forwarded-host and x-forwarded-proto headers.
  • Request validation is updated to verify the validity of Forwarded host and proto parameters.
  • Request sanitization is updated to scrub or retain the Forwarded header based on the configured trusted proxy headers.

Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Forwarded

@alan-agius4 alan-agius4 requested a review from dgp1130 June 18, 2026 08:01
@alan-agius4 alan-agius4 added the target: minor This PR is targeted for the next minor release label Jun 18, 2026
@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: @angular/ssr labels Jun 18, 2026
@alan-agius4 alan-agius4 force-pushed the feat/forwarded-header branch from ff18569 to fdb4c43 Compare June 18, 2026 08:03

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for parsing and validating the standard RFC 7239 Forwarded header in Angular SSR, prioritizing it over standard and x-forwarded-* headers when trusted. The review feedback highlights a critical issue in parseForwardedHeader where splitting the header value by semicolons blindly fails if a quoted parameter value contains a semicolon. The reviewer suggests using a robust regular expression to parse the parameters correctly and adding a corresponding test case to cover this scenario.

Comment thread packages/angular/ssr/src/utils/validation.ts
Comment thread packages/angular/ssr/node/test/request_spec.ts
This commit adds support for the standard RFC 7239 `Forwarded` header in the Angular SSR request parsing and validation layers.

Previously, only non-standard `x-forwarded-*` headers were supported for resolving proxy-forwarded protocols, hosts, and ports. With this change:
- A new `parseForwardedHeader` utility is added to parse standard `Forwarded` header parameters (such as `host` and `proto`), correctly handling quoted values and escaped characters.
- In `createRequestUrl`, if the `Forwarded` header is trusted (via `trustProxyHeaders` configuration), its `host` and `proto` parameters are extracted and take precedence over corresponding `x-forwarded-host` and `x-forwarded-proto` headers.
- Request validation is updated to verify the validity of `Forwarded` host and proto parameters.
- Request sanitization is updated to scrub or retain the `Forwarded` header based on the configured trusted proxy headers.

Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Forwarded
@alan-agius4 alan-agius4 force-pushed the feat/forwarded-header branch from fdb4c43 to 9b93c32 Compare June 18, 2026 08:09
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jun 18, 2026
Comment thread packages/angular/ssr/src/utils/validation.ts Outdated
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jun 23, 2026
@alan-agius4 alan-agius4 merged commit 7ef9ed2 into angular:main Jun 23, 2026
67 of 68 checks passed
@alan-agius4 alan-agius4 deleted the feat/forwarded-header branch June 23, 2026 08:45
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

kirjs pushed a commit to angular/angular that referenced this pull request Jun 23, 2026
Update the security guide to document that the Angular SSR request handling pipeline now supports and validates the standard RFC 7239 `Forwarded` header.

Previously, only non-standard `X-Forwarded-*` headers were supported for resolving proxy-forwarded protocols, hosts, and ports. With this update:
- The standard `Forwarded` header parameters (such as `host` and `proto`) are validated and take precedence over corresponding `X-Forwarded-*` headers when trusted.
- The `trustProxyHeaders` option and `NG_TRUST_PROXY_HEADERS` environment variable can be configured to trust the `Forwarded` header.

For more details on the implementation, see the corresponding PR:
angular/angular-cli#33406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/ssr detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants