gateway icon indicating copy to clipboard operation
gateway copied to clipboard

OIDC: let the nonce and code-verifier cookies use Path=/ so all OAuth2 cookies can carry the __Host- prefix

Open peterekhator opened this issue 1 month ago • 1 comments

Description:

With #9755 (fixes #9744), a SecurityPolicy can name every OAuth2 cookie, so a user can give them the __Host- prefix and stop a sibling host on the same registrable domain from planting or shadowing them (for example a refresh-token cookie set with Domain= by another subdomain, which would log the victim into the attacker's session).

Two of the seven cookies still can't take the prefix. The translator sets the nonce and code-verifier cookies' path to the redirect path (buildCookieConfigs in internal/xds/translator/oidc.go), and browsers reject a __Host- cookie unless it has Path=/. So cookieNames.oauthNonce: __Host-... or cookieNames.codeVerifier: __Host-... produces a cookie the browser silently drops, and the login flow fails at the callback.

Scoping those two cookies to the callback path is a sensible default, so we'd like an opt-out rather than a change of default. Either of these would work:

  1. A path field on OIDCCookieConfig (alongside sameSite), applied to the nonce and code-verifier cookies, mapped to Envoy's CookieConfig.path (envoyproxy/envoy#41929).
  2. When the nonce or code-verifier name starts with __Host-, set that cookie's path to / automatically, since no other path can work.

Option 2 needs no API change. Option 1 is more general. Either way, a CEL rule that rejects a __Host- name combined with a non-/ path would surface the mistake at admission instead of at the user's browser.

We can open a PR for whichever option maintainers prefer.

Related: would maintainers accept a backport of #9755 to release/v1.9? Until v1.10, the only way to rename the other five cookies on 1.9.x is an EnvoyPatchPolicy on the route's typed_per_filter_config (credentials.cookie_names.* and cookie_configs.*.path), which we run today and would like to drop.

[optional Relevant Links:]

  • #9744, #9755 (full cookie name overrides, merged to main after v1.9.2)
  • envoyproxy/envoy#41929 (oauth2 CookieConfig.path)
  • RFC 6265bis, cookie name prefixes: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis#name-cookie-name-prefixes

peterekhator avatar Oct 16 '26 16:10 peterekhator

This issue has been automatically marked as stale because it has not had activity in the last 30 days.

github-actions[bot] avatar Nov 15 '26 20:11 github-actions[bot]