Skip to content

Fix ZonePathContextRewritingFilter rewriting __Host- cookie paths - #4048

Merged
duanemay merged 1 commit into
cloudfoundry:developfrom
joemahady-comm:TNZ-134079
Aug 24, 2026
Merged

Fix ZonePathContextRewritingFilter rewriting __Host- cookie paths#4048
duanemay merged 1 commit into
cloudfoundry:developfrom
joemahady-comm:TNZ-134079

Conversation

@joemahady-comm

Copy link
Copy Markdown
Contributor

RFC 6265bis requires __Host- prefixed cookies to unconditionally have Path=/. The ZonePathContextRewritingFilter was incorrectly mutating the path of these cookies to the zone context path (e.g. /auth), causing browsers to reject them and resulting in CSRF token mismatch errors.

This change updates the filter to exclude __Host- prefixed cookies from path rewriting, ensuring they retain their required Path=/ attribute.

@joemahady-comm

Copy link
Copy Markdown
Contributor Author

Issue reproduced:

/uaa path incorrectly set:

_Host-X-Uaa-Csrf=РiYRIET5anaSЗЗdLLcNU4D; Expires=Tue, 25 Aug 2026 08:28:08 GMT; Max-Age=86400; Path=/uaa; Secure; HttpOnly;

invalid_login_request

Issue fixed:

/ path now correctly set:

_Host-X-Uaa-Csrf=HgiqY4zO\WrTOwYAe3HgFV; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/; Secure; HttpOnly; SameSite=Lax

login_success

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes zone-path cookie rewriting for __Host--prefixed cookies in ZonePathContextRewritingFilter, aligning behavior with RFC 6265bis by ensuring these cookies keep Path=/ and aren’t rejected by browsers (avoiding downstream CSRF token mismatches).

Changes:

  • Skip cookie path rewriting for __Host- cookies when adding Cookie objects to the response.
  • Skip Set-Cookie header path rewriting for __Host- cookie names.
  • Add regression tests covering both addCookie(...) and addHeader("Set-Cookie", ...) cases for __Host- cookies.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
server/src/main/java/org/cloudfoundry/identity/uaa/zone/ZonePathContextRewritingFilter.java Excludes __Host- cookies from path rewriting for both Cookie objects and Set-Cookie headers.
server/src/test/java/org/cloudfoundry/identity/uaa/zone/ZonePathContextRewritingFilterTests.java Adds regression tests to ensure __Host- cookie paths remain / under zone-path requests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

RFC 6265bis requires `__Host-` prefixed cookies to unconditionally have `Path=/`.
The `ZonePathContextRewritingFilter` was incorrectly mutating the path of these
cookies to the zone context path (e.g. `/auth`), causing browsers to reject them
and resulting in CSRF token mismatch errors.

This change updates the filter to exclude `__Host-` prefixed cookies from path
rewriting, ensuring they retain their required `Path=/` attribute.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@joemahady-comm

Copy link
Copy Markdown
Contributor Author

Requesting review from @strehle @duanemay @fhanik

@strehle
strehle requested review from duanemay and fhanik August 24, 2026 13:08
@github-project-automation github-project-automation Bot moved this from Inbox to Pending Merge | Prioritized in Foundational Infrastructure Working Group Aug 24, 2026
@duanemay
duanemay merged commit 09e820c into cloudfoundry:develop Aug 24, 2026
26 checks passed
@github-project-automation github-project-automation Bot moved this from Pending Merge | Prioritized to Done in Foundational Infrastructure Working Group Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

4 participants