Skip to content

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

Open
alan-agius4 wants to merge 1 commit intoangular:20.3.xfrom
alan-agius4:prefix-fix
Open

fix(@angular/ssr): decode x-forwarded-prefix before validation#32906
alan-agius4 wants to merge 1 commit intoangular:20.3.xfrom
alan-agius4:prefix-fix

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.

@alan-agius4 alan-agius4 requested a review from dgp1130 March 31, 2026 12:43
@alan-agius4 alan-agius4 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 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 of the x-forwarded-prefix header validation by decoding the header value before applying regex checks, preventing potential bypasses via URL encoding. It also introduces new test cases to verify the handling of encoded malicious prefixes and malformed URI components. A review comment correctly identified a function signature mismatch in the newly added tests where validateRequest was called with an extraneous third argument.

@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 validation of the "x-forwarded-prefix" header by decoding the value before checking it against invalid path patterns, ensuring that encoded malicious paths are correctly identified. It also includes updated test cases for encoded prefixes and malformed URI components. A security improvement was suggested to trim the decoded prefix to prevent potential bypasses using encoded whitespace characters.

@alan-agius4
Copy link
Copy Markdown
Collaborator Author

/gemini review

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.
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 validation of the x-forwarded-prefix header in the Angular SSR utility by decoding and trimming the header value before performing security checks. It also introduces error handling for malformed URI components and expands the test suite to include encoded malicious paths and invalid encoding scenarios. I have no feedback to provide.

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: 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