fix: Prevent cookie accumulation when domain config varies #2462
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