Skip to content

fix(@angular/ssr): decode x-forwarded-prefix before validation#32904

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

fix(@angular/ssr): decode x-forwarded-prefix before validation#32904
alan-agius4 wants to merge 2 commits intoangular:mainfrom
alan-agius4:security-x-prefix

Conversation

@alan-agius4
Copy link
Copy Markdown
Collaborator

The x-forwarded-prefix header can be percent-encoded. Validating it without decoding can allow bypassing security checks if subsequent processors (such as the URL constructor or a browser) implicitly decode it.

Key bypass scenarios addressed:

  • Implicit Decoding by URL Parsers: A regex check for a literal .. might miss %2e%2e. However, if the prefix is later passed to a URL constructor, it will treat %2e%2e as .., climbing up a directory.
  • Browser Role in Redirects: If an un-decoded encoded path is sent in a Location header, the browser will decode it, leading to unintended navigation.
  • Double Slash Bypass: Checking for a literal // misses %2f%2f. URL parsers might treat leading double slashes as protocol-relative URLs, leading to Open Redirects if interpreted as a hostname.

This change ensures the validation "speaks the same language" as the URL parsing system by decoding the prefix before running safety checks. It also introduces robust handling for malformed percent-encoding.

The `x-forwarded-prefix` header can be percent-encoded. Validating it without decoding can allow bypassing security checks if subsequent processors (such as the `URL` constructor or a browser) implicitly decode it.

Key bypass scenarios addressed:
- **Implicit Decoding by URL Parsers**: A regex check for a literal `..` might miss `%2e%2e`. However, if the prefix is later passed to a `URL` constructor, it will treat `%2e%2e` as `..`, climbing up a directory.
- **Browser Role in Redirects**: If an un-decoded encoded path is sent in a `Location` header, the browser will decode it, leading to unintended navigation.
- **Double Slash Bypass**: Checking for a literal `//` misses `%2f%2f`. URL parsers might treat leading double slashes as protocol-relative URLs, leading to Open Redirects if interpreted as a hostname.

This change ensures the validation "speaks the same language" as the URL parsing system by decoding the prefix before running safety checks. It also introduces robust handling for malformed percent-encoding.
@alan-agius4 alan-agius4 requested a review from dgp1130 March 31, 2026 08:44
@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 31, 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 enhances the security validation of the 'x-forwarded-prefix' header by decoding its value before performing regex checks. This change ensures that URL-encoded malicious path segments or prefixes are correctly identified. It also introduces error handling for malformed URI components and includes updated test cases to verify the new decoding and validation logic. I have no feedback to provide as there were no review comments.

@alan-agius4
Copy link
Copy Markdown
Collaborator Author

/gemini review

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 enhances the security validation of the x-forwarded-prefix header by decoding it before applying regex checks, which prevents potential bypasses using URL-encoded characters. It also introduces error handling for malformed URI components and expands the test suite. Feedback suggests further strengthening the tests by explicitly including additional encoded path segments such as %2e%2e and %2e to ensure comprehensive coverage.

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.

1 participant