Skip to content

fix(@angular/ssr): disallow x-forwarded-prefix starting with a backslash#32771

Open
alan-agius4 wants to merge 2 commits intoangular:mainfrom
alan-agius4:prefix-url
Open

fix(@angular/ssr): disallow x-forwarded-prefix starting with a backslash#32771
alan-agius4 wants to merge 2 commits intoangular:mainfrom
alan-agius4:prefix-url

Conversation

@alan-agius4
Copy link
Collaborator

Updated the INVALID_PREFIX_REGEX to ensure that prefixes starting with a backslash are considered invalid. Previously, only multiple slashes or dot segments were explicitly disallowed at the start.

Also updated the associated validation error message and unit tests to reflect this change.

@alan-agius4 alan-agius4 requested a review from dgp1130 March 16, 2026 09:20
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Mar 16, 2026
Copy link

@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 correctly addresses a validation gap by disallowing x-forwarded-prefix headers that start with a backslash. The regular expression has been updated effectively, and a corresponding test case has been added to cover this scenario. My review includes a few suggestions to improve the clarity of the error message and a related test description to ensure they accurately reflect all invalid prefix conditions being checked.

Updated the INVALID_PREFIX_REGEX to ensure that prefixes starting with a backslash are considered invalid. Previously, only multiple slashes or dot segments were explicitly disallowed at the start.

Also updated the associated validation error message and unit tests to reflect this change.
@alan-agius4 alan-agius4 force-pushed the prefix-url branch 2 times, most recently from c0bb10a to 2210255 Compare March 16, 2026 13:02
Updates createRedirectResponse to accept an optional Record<string, string> of headers, allowing custom headers to be merged into the redirect response. The Location and Vary: X-Forwarded-Prefix headers are automatically set to ensure correct routing and proxy behavior.

AngularServerApp now passes relevant headers from the matched route or response context when creating a redirect.
* Regular expression to validate that the prefix is valid.
*/
const INVALID_PREFIX_REGEX = /^[/\\]{2}|(?:^|[/\\])\.\.?(?:[/\\]|$)/;
const INVALID_PREFIX_REGEX = /^\\|^\/[/\\]|(?:^|[/\\])\.\.?(?:[/\\]|$)/;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Parens might make the order of operations clearer, /(^\\|^\/)[/\\].../

headers: {
...headers,
'Location': location,
'Vary': 'X-Forwarded-Prefix',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider: What if someone tries to set Vary: foo, seems like we'd override with our Vary: X-Forwarded-Prefix. Should we merge that to Vary: X-Forwarded-Prefix, foo?

status,
headers: {
...headers,
'Location': location,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Should we warn or error (probably limited to ngDevMode) if the user specifies a Location header given that we'll ignore it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/ssr target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants