Skip to content

fix(@angular/ssr): add support for configuring trusted proxy headers via environment variable#33272

Open
dgp1130 wants to merge 1 commit into
angular:20.3.xfrom
dgp1130:trust-proxy-headers-env-v20
Open

fix(@angular/ssr): add support for configuring trusted proxy headers via environment variable#33272
dgp1130 wants to merge 1 commit into
angular:20.3.xfrom
dgp1130:trust-proxy-headers-env-v20

Conversation

@dgp1130
Copy link
Copy Markdown
Collaborator

@dgp1130 dgp1130 commented May 29, 2026

This is a v20 port of #33056.

Adds support for configuring trusted proxy headers via the NG_TRUST_PROXY_HEADERS environment variable in AngularNodeAppEngine. This allows users to specify which proxy headers (such as X-Forwarded-Host) should be trusted when running the server-side application behind a reverse proxy, without needing to modify the application code. The environment variable accepts a comma-separated list of header names. If the NG_TRUST_PROXY_HEADERS environment variable is set and contains non-empty values, it will take precedence over the trustProxyHeaders option provided programmatically in the AngularNodeAppEngine constructor options.

(cherry picked from commit 126b19b)

…via environment variable

Adds support for configuring trusted proxy headers via the `NG_TRUST_PROXY_HEADERS` environment variable in `AngularNodeAppEngine`.
This allows users to specify which proxy headers (such as `X-Forwarded-Host`) should be trusted when running the server-side application behind a reverse proxy, without needing to modify the application code. The environment variable accepts a comma-separated list of header names.
If the `NG_TRUST_PROXY_HEADERS` environment variable is set and contains non-empty values, it will take precedence over the `trustProxyHeaders` option provided programmatically in the `AngularNodeAppEngine` constructor options.

(cherry picked from commit 126b19b)
@dgp1130 dgp1130 requested a review from alan-agius4 May 29, 2026 15:50
@dgp1130 dgp1130 added action: review The PR is still awaiting reviews from at least one requested reviewer target: lts This PR is targeting a version currently in long-term support area: @angular/ssr labels May 29, 2026
Copy link
Copy Markdown

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

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 refactors environment variable parsing to support trusted proxy headers (NG_TRUST_PROXY_HEADERS) alongside allowed hosts (NG_ALLOWED_HOSTS). However, the changes in AngularNodeAppEngine and CommonEngine switch from merging environment-configured hosts with programmatic options to overriding them entirely. The reviewer noted that this is a breaking change and suggested reverting to merging both sources to preserve backward compatibility.

allowedHosts: [...getAllowedHostsFromEnv(), ...(options?.allowedHosts ?? [])],
});
this.trustProxyHeaders = options?.trustProxyHeaders;
allowedHosts: getAllowedHostsFromEnv() ?? options?.allowedHosts,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Changing 'allowedHosts' to use the nullish coalescing operator ('??') changes the behavior from merging the environment variable hosts with the programmatic options to completely overriding them. This is a breaking change for deployments that rely on both sources. To preserve backward compatibility, we should continue to merge them.

      allowedHosts: [
        ...(getAllowedHostsFromEnv() ?? []),
        ...(options?.allowedHosts ?? []),
      ],

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@alan-agius4, this is seems like reasonable feedback, though I'm hesitant to diverge this PR from the one it's porting, maybe this is a separate fix we should consider landing?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this was done based on your feedback, so also keep the same behaviour between trustProxyHeaders and allowedHosts.

Comment thread packages/angular/ssr/node/src/common-engine/common-engine.ts
@dgp1130 dgp1130 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 May 29, 2026
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 target: lts This PR is targeting a version currently in long-term support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants