Add cookie chunking support for sessions exceeding 4KB limit#937
Open
sefasenturk95 wants to merge 2 commits intovvo:mainfrom
Open
Add cookie chunking support for sessions exceeding 4KB limit#937sefasenturk95 wants to merge 2 commits intovvo:mainfrom
sefasenturk95 wants to merge 2 commits intovvo:mainfrom
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? 🙈 |
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."