-
Notifications
You must be signed in to change notification settings - Fork 432
Fix updateSession
and header overwrite issues
#2330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tusharpandey13
wants to merge
7
commits into
main
Choose a base branch
from
debug/updateSession-empty-cookie
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
…t; perviously this was setting a SetCookie header with maxAge=0 for each call to updateSession()
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2330 +/- ##
==========================================
+ Coverage 85.47% 86.57% +1.10%
==========================================
Files 26 26
Lines 2636 2652 +16
Branches 486 497 +11
==========================================
+ Hits 2253 2296 +43
+ Misses 377 350 -27
Partials 6 6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
updateSession
setting unnecessary Max-Age=0
cookies
6 tasks
…er() was called with multiple entries of set-ccokie header key, leading to the latest entries overwriting old entries, leading to missing cookies
…/auth0/nextjs-auth0 into debug/updateSession-empty-cookie
updateSession
setting unnecessary Max-Age=0
cookiesupdateSession
and header overwrite issues
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.
📋 Changes
This PR implements three complementary fixes to resolve updateSession reliability issues:
Fixed race condition in timestamp calculations - Eliminated inconsistent
maxAge
values by using the sameupdatedAt
timestamp throughoutcalculateMaxAge()
instead of callingthis.epoch()
twice, preventingMax-Age=0
cookies from timing inconsistenciessrc/server/session/abstract-session-store.ts
Implemented conditional legacy cookie cleanup - Added existence check before deleting legacy cookies to prevent unnecessary
Max-Age=0
cookies appearing in response headers duringupdateSession()
callssrc/server/session/stateless-session-store.ts
src/server/session/stateless-session-store.test.ts
(updated test mocks)Fixed header overwrite in Pages Router - Resolved session chunk loss by collecting all
set-cookie
headers into an array before setting them, preventingres.setHeader()
from overwriting multiple cookiessrc/server/client.ts
src/server/updateSession-header-fix.test.ts
(comprehensive test suite)📎 References
Fixes: #2316
🎯 Testing
Automated:
getChunkedCookie()
properly for legacy cookie scenariosupdateSession-header-fix.test.ts
covering multiple set-cookie header scenarios, legacy cookie deletion, and edge casesManual:
updateSession(req, res, session)
with chunked session dataconsole.log(res.getHeaders())
immediately after theupdateSession()
call'set-cookie': ['appSession=; Path=/; Max-Age=0']
(unnecessary deletion) or missing session chunks (header overwrite)Max-Age=0
deletion cookies