Skip to content

feat: chunk large OIDC token cookies by default - #10402

Merged
zhaohuabing merged 3 commits into
envoyproxy:mainfrom
nobbs:feat/oidc-token-cookie-chunking-default
Oct 27, 2026
Merged

zhaohuabing merged 3 commits into
envoyproxy:mainfrom
nobbs:feat/oidc-token-cookie-chunking-default

Conversation

@nobbs

@nobbs nobbs commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Supersedes #10326, following @zhaohuabing's suggestion there. Instead of a per-policy tokenCookieChunking field, Envoy Gateway sets the OAuth2 filter's token_cookie_chunking (envoyproxy/envoy#48086, in Envoy v1.40.0) on every OIDC filter, with Envoy's default limits. A new runtime flag, OIDCTokenCookieChunking, enabled by default, turns it off.

Browsers silently drop a cookie larger than 4096 bytes. When the OIDC provider issues a larger access, ID or refresh token, for example one carrying many group claims, the session cookie never comes back and the user is redirected to the provider again and again. With chunking, Envoy splits such a token into <name>_0 .. <name>_N-1 cookies plus a <name>_chunks count cookie, and rejoins them before the HMAC check.

 gatewayapi runner
   Translator{OIDCTokenCookieChunkingDisabled: !runtimeFlags.IsEnabled(OIDCTokenCookieChunking)}
     buildOIDC
+      ir.OIDC.TokenCookieChunking = !OIDCTokenCookieChunkingDisabled
 xds translator
   oauth2Config
+    token_cookie_chunking: {}   # Envoy defaults: 4096 bytes per cookie, at most 8 chunks

Why on by default:

  • A token that fits in one cookie is written as before, byte for byte. Nothing changes until a token exceeds one cookie, and such a token already breaks the login in a browser today.
  • Envoy made chunking opt-in because a runtime guard is removed after a few releases, which takes away the safe upgrade path for a mixed fleet. Each Envoy Gateway release pins one Envoy minor, so once every supported upgrade starts from a release whose Envoy reads chunks, the flag can go.

What the flag is for: Envoy older than v1.40 can't read split cookies. While an older proxy serves the same hostname, during the rollout or while the clusters of a multi-cluster setup are upgraded one by one, a client that holds such a token in one cookie today is sent back to the provider when it reaches the older proxy. That client is a non-browser client, or a browser whose token is just under the limit, since Envoy counts the cookie attributes and browsers don't. The docs and the release note say to disable the flag until every proxy is upgraded.

Differences from #10326:

Tests:

  • TestTranslate: every OIDC golden now carries tokenCookieChunking: true in the IR. All 11 fail with the translator change reverted. The new securitypolicy-with-oidc-token-cookie-chunking-disabled golden covers the flag turned off and fails if the translator ignores the flag.
  • TestTranslateXds/oidc: token_cookie_chunking: {} on the first route, absent on the second. Fails without the xDS change.
  • TestOIDCTokenCookieChunkingRuntimeFlag: enabled by default, off through runtimeFlags.disabled.
  • e2e, carried over from feat: support OIDC token cookie chunking #10326: a Keycloak client whose access token carries a 6000-character claim (9302 characters in total), on a route with refreshToken: false, so a lost access token cookie can't be recovered through a refresh. The test client now ignores a cookie whose name and value exceed 4096 bytes and stops after 20 redirects, as a browser does. The test checks the token arrives as AccessToken-…_N chunks plus AccessToken-…_chunks, and that the session works without a second login. On feat: support OIDC token cookie chunking #10326, the same case without chunking failed with stopped after 20 redirects, the loop reported in OIDC: Redirect loop of OIDC Authentication due to the cookie length limit #7315.

Merge danger: a two-way door. The flag turns the behavior off without a release, and Envoy keeps reading split cookies with the field unset, so neither turning it off nor reverting this PR ends existing sessions. The blast radius is every OIDC route, limited to tokens larger than one cookie.

Which issue(s) this PR fixes:

Fixes #7315


PR Checklist

  • Authorship & ownership: Coding agents / AI assistants are welcome, but I have reviewed every change, understand how and why it works, can explain and maintain it, and take full responsibility for this PR. I have not submitted generated output I do not understand.
  • DCO: All commits are signed off (git commit -s). See DCO: Sign your work.
  • API agreed first: If this PR contains API changes (changes under /api), the API was discussed and agreed before the implementation. The API change can be in a separate PR, or in the same PR, but the API must be agreed before implementation. N/A if this PR does not contain API changes. (The only API change is the OIDCTokenCookieChunking runtime flag @zhaohuabing proposed on feat: support OIDC token cookie chunking #10326.)
  • Required checks pass: make generate gen-check, make lint, and the unit-test/coverage build pass. (Flaky e2e failures are not considered breakages, but gen-check, lint, and coverage MUST pass.) (gen-check, lint and the coverage tests pass locally.)
  • Tests added/updated: New/changed code is covered by appropriate tests. N/A if this PR does not contain code changes.
  • Docs: User-facing changes update the docs, either in this PR or a follow-up PR. N/A if this PR does not contain user-facing changes.
  • Release notes: For any non-trivial change, added a release-note fragment under release-notes/current/<section>/<pr-number>-<slug>.md (see release-notes/current/README.md for sections and naming). N/A if this PR does not contain non-trivial changes.
  • Generated files committed: Ran make gen-check and committed the result if API/helm charts/modules changed.
  • Scope & compatibility: The PR is reasonably scoped (no unrelated changes) and preserves backward compatibility, or any breaking change is called out above and documented in release-notes/current/breaking_changes/. (Chunking is on by default; the upgrade window is called out above, in the docs and in the release note.)
  • Codex review: Requested a Codex review and addressed all of its comments.
  • Copilot review: Requested a Copilot review and addressed all of its comments.

nobbs added 3 commits October 26, 2026 09:57
Sets token_cookie_chunking with Envoy's default limits on every OIDC
filter, so Envoy splits an access, ID or refresh token too large for one
browser cookie across several cookies, instead of the browser dropping it
and the login looping back to the OIDC provider. A token that fits is
still written as one cookie, byte for byte as before.

The OIDCTokenCookieChunking runtime flag, enabled by default, turns it
off. Envoy older than v1.40 can't read the split cookies, so operators
disable the flag while proxies of an earlier release serve the same
hostnames, for example during an upgrade.

Refs: envoyproxy#7315
Signed-off-by: Alexej Disterhoft <[email protected]>
Adds a "Large Tokens" section to the OIDC task: the login loop a token
over 4096 bytes caused, how Envoy now splits it and within which limits,
the request header limit to watch, and when to disable the
OIDCTokenCookieChunking runtime flag. Adds the release note.

Refs: envoyproxy#7315
Signed-off-by: Alexej Disterhoft <[email protected]>
Adds a Keycloak client whose access token carries a 6000-character
claim, and an OIDC route for it with refresh tokens off, so a dropped
access token cookie cannot be papered over by a refresh. The test checks
the token arrives as "<name>_N" chunks plus a "<name>_chunks" count
cookie and that the session works from them.

The OIDC test client now behaves like a browser in the two ways this
depends on: it ignores a cookie whose name and value exceed 4096 bytes,
and it gives up after 20 redirects instead of following a login loop
until the test times out. Without chunking the new case fails with
"stopped after 20 redirects", the loop reported in envoyproxy#7315.

Refs: envoyproxy#7315
Signed-off-by: Alexej Disterhoft <[email protected]>
@nobbs
nobbs requested a review from a team as a code owner October 26, 2026 09:11
@netlify

netlify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit 5105c3b
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6adf1943f2cddc8fd75ea806
😎 Deploy Preview https://deploy-preview-10402--cerulean-figolla-1f9435.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T09:20:07.466426Z 5105c3b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5105c3b67c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +249 to +250
if oidc.TokenCookieChunking {
oauth2.Config.TokenCookieChunking = &oauth2v3.TokenCookieChunking{}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate generated chunk cookie names before enabling chunking

When a valid SecurityPolicy names the access-token cookie session and another OIDC cookie session_0 or session_chunks, the existing OIDCCookieNames uniqueness rule accepts the distinct base names. Once the access token is large enough to be chunked, this setting makes Envoy generate those same names for the first chunk or chunk count, so one cookie value overwrites the other and the OIDC session cannot be validated. Reserve the generated _<index>/_chunks names during admission or translation before enabling this config.

Useful? React with 👍 / 👎.

@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.12%. Comparing base (4e77313) to head (5105c3b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10402      +/-   ##
==========================================
- Coverage   82.12%   82.12%   -0.01%     
==========================================
  Files         272      272              
  Lines       43156    43160       +4     
==========================================
  Hits        35443    35443              
- Misses       7712     7716       +4     
  Partials        1        1              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zhaohuabing zhaohuabing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks!

@zhaohuabing
zhaohuabing requested a review from a team October 27, 2026 02:43
@zhaohuabing zhaohuabing added this to the v1.10.0-rc.1 Release milestone Oct 27, 2026
@zhaohuabing
zhaohuabing requested a review from a team October 27, 2026 03:34
@zhaohuabing
zhaohuabing merged commit 4ec0fbb into envoyproxy:main Oct 27, 2026
76 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OIDC: Redirect loop of OIDC Authentication due to the cookie length limit

3 participants