Add cookie chunking support for sessions exceeding 4KB limit - #937
Open
sefasenturk95 wants to merge 2 commits into
Open
Add cookie chunking support for sessions exceeding 4KB limit#937sefasenturk95 wants to merge 2 commits into
sefasenturk95 wants to merge 2 commits into
Conversation
This adds optional cookie chunking to handle session data that exceeds
browser cookie size limits (~4KB). When enabled, large cookies are
automatically split into multiple smaller cookies and reconstructed
transparently when reading.
Features:
- Opt-in via chunking config: { enabled: true, chunkSize: 3500 }
- Automatic chunking when session exceeds chunk size
- Transparent reconstruction from chunks on read
- Automatic cleanup of old chunks on save/destroy
- Works with both Node.js req/res and CookieStore patterns
- Backward compatible with existing non-chunked sessions
Chunk naming pattern: {cookieName}.0, {cookieName}.1, etc.
Includes comprehensive test coverage with 6 new test cases.
|
@sefasenturk95 is attempting to deploy a commit to the Codeagain Team on Vercel. A member of the Team first needs to authorize it. |
- Add type assertions (as any) to collectAllCookies calls to fix mock type mismatch - Add non-null assertions for array access in test assertions - Fixes prepare script errors during npm install
Author
|
@vvo could you take a look at this please? :) Thanks in advance! |
Author
|
@vvo hello? Anyone there? 🙈 |
17 tasks
1 task
ThomasGross
added a commit
to danskernesdigitalebibliotek/dpl-web
that referenced
this pull request
Jun 10, 2026
The Unilogin session (access + refresh + id token) overflows the 4096 byte browser cookie limit, breaking sign-in. Wrap iron-session's exported sealData/unsealData and split the seal across go-session.0, go-session.1, ... when it would otherwise exceed the limit. Mirrors the approach in the unmerged upstream PR vvo/iron-session#937 so we can drop the wrapper once that lands.
xendk
pushed a commit
to danskernesdigitalebibliotek/dpl-web
that referenced
this pull request
Jun 10, 2026
The go-session cookie holds two JWTs (access + refresh) plus PKCE and profile fields, and we are hitting the 4 KB per-cookie browser limit for some users. Iron-session 8.0.4 has no built-in workaround and the upstream fix is unreviewed (vvo/iron-session#937). Apply that PR as a patch-package patch against an exact-pinned iron-session@8.0.4 so chunking is available without forking, and enable it in getSessionOptions. With chunking on, iron-session keeps a single go-session cookie when the sealed value fits, and otherwise splits it into go-session.0, go-session.1, ... transparently on read. Letting CI fail on a future Dependabot bump is the intended signal to refresh or drop the patch when upstream merges. To reproduce the patch file (iron-session ships only compiled dist/*, so we cannot patch the source files referenced by PR #937 directly): # 1. Get the iron-session source at v8.0.4 with PR #937 applied. git clone https://github.com/vvo/iron-session.git cd iron-session git fetch origin pull/937/head:pr-937 git diff v8.0.4..pr-937 -- src/core.ts > /tmp/pr-937-core.diff git checkout v8.0.4 git apply /tmp/pr-937-core.diff # 2. Build dist/* with the upstream toolchain. npm install --ignore-scripts npx tsup # 3. Copy the built dist into this project's node_modules and let # patch-package capture the diff against the published 8.0.4. cp dist/* <dpl-web>/go/node_modules/iron-session/dist/ cd <dpl-web>/go npx patch-package iron-session This keeps the committed patch bit-for-bit faithful to what upstream would publish if PR #937 merged, rather than hand-translating TypeScript changes into compiled output. Assisted-by: Claude <noreply@anthropic.com>
xendk
pushed a commit
to danskernesdigitalebibliotek/dpl-web
that referenced
this pull request
Jun 10, 2026
The go-session cookie holds two JWTs (access + refresh) plus PKCE and profile fields, and we are hitting the 4 KB per-cookie browser limit for some users. Iron-session 8.0.4 has no built-in workaround and the upstream fix is unreviewed (vvo/iron-session#937). Apply that PR as a patch-package patch against an exact-pinned iron-session@8.0.4 so chunking is available without forking, and enable it in getSessionOptions. With chunking on, iron-session keeps a single go-session cookie when the sealed value fits, and otherwise splits it into go-session.0, go-session.1, ... transparently on read. Letting CI fail on a future Dependabot bump is the intended signal to refresh or drop the patch when upstream merges. To reproduce the patch file (iron-session ships only compiled dist/*, so we cannot patch the source files referenced by PR #937 directly): # 1. Get the iron-session source at v8.0.4 with PR #937 applied. git clone https://github.com/vvo/iron-session.git cd iron-session git fetch origin pull/937/head:pr-937 git diff v8.0.4..pr-937 -- src/core.ts > /tmp/pr-937-core.diff git checkout v8.0.4 git apply /tmp/pr-937-core.diff # 2. Build dist/* with the upstream toolchain. npm install --ignore-scripts npx tsup # 3. Copy the built dist into this project's node_modules and let # patch-package capture the diff against the published 8.0.4. cp dist/* <dpl-web>/go/node_modules/iron-session/dist/ cd <dpl-web>/go npx patch-package iron-session This keeps the committed patch bit-for-bit faithful to what upstream would publish if PR #937 merged, rather than hand-translating TypeScript changes into compiled output. Assisted-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds optional cookie chunking to handle session data that exceeds browser cookie size limits (~4KB). When enabled, large cookies are automatically split into multiple smaller cookies and reconstructed transparently when reading.
Multiple users have reported hitting the 4096-byte cookie size limit with iron-session:
Currently, users hitting this limit must either:
This PR provides a third option: automatic cookie chunking for moderate-sized sessions that don't warrant the complexity of external storage.
Changes:
splitCookieIntoChunks()for splitting large cookiesreconstructCookie()andreconstructCookieWithStore()for transparent reassemblysave()method to handle chunking for both Node.js and CookieStore patternsdestroy()method to clean up all chunksDocumentation:
Testing:
Note: This PR addresses a common pain point while maintaining iron-session's stateless, cookie-based architecture. It's a middle-ground solution between "reduce your data" and "switch to Redis."