fix: Prevent cookie accumulation when domain config varies#2462
Open
tusharpandey13 wants to merge 2 commits intomainfrom
Open
fix: Prevent cookie accumulation when domain config varies#2462tusharpandey13 wants to merge 2 commits intomainfrom
tusharpandey13 wants to merge 2 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2462 +/- ##
==========================================
+ Coverage 90.99% 91.13% +0.14%
==========================================
Files 39 39
Lines 4520 4661 +141
Branches 939 945 +6
==========================================
+ Hits 4113 4248 +135
- Misses 401 407 +6
Partials 6 6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Problem
When
AUTH0_COOKIE_DOMAINis configured (e.g.,.example.com), cookies can accumulate instead of being replaced, eventually causingHTTP 431errors.Per RFC 6265, cookies are unique by
(name, domain, path). When the SDK deletes cookies, it only emits aSet-Cookieheader matching the current domain configuration—leaving orphaned cookies from prior configurations or middleware/route handler mismatches.Changes
When a domain is configured, cookie deletion now emits two
Set-Cookieheaders:Set-Cookie: __session=; Domain=.example.com; Max-Age=0Set-Cookie: __session=; Max-Age=0(no Domain attribute)This ensures both cookie variants are cleared, preventing accumulation regardless of how the cookie was originally set.
An optional
rawHeadersparameters is used for cookie set/delete operations.cookies.ts:deleteCookie(),deleteChunkedCookie(),setChunkedCookie()accept optionalrawHeadersparam; emit dual deletion headers when domain configuredabstract-session-store.ts: Updatedset()/delete()signatures withrawHeadersparamstateless-session-store.ts: PropagaterawHeadersto cookie functionsstateful-session-store.ts: PropagaterawHeadersto cookie functionstransaction-store.ts: Updateddelete()/deleteAll()withrawHeadersparamauth-client.ts: Passres.headersto all 12 session/transaction store call sitesclient.ts: PassrawHeadersin middleware and pages router pathsTesting
9 new flow tests covering dual-domain deletion behavior