Add cookie chunking support for sessions exceeding 4KB limit #937
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."