fix(cookies): use lookahead heuristic for splitting Set-Cookie headers#8301
Merged
fix(cookies): use lookahead heuristic for splitting Set-Cookie headers#8301
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
@better-auth/api-key
better-auth
auth
@better-auth/core
@better-auth/drizzle-adapter
@better-auth/electron
@better-auth/expo
@better-auth/i18n
@better-auth/kysely-adapter
@better-auth/memory-adapter
@better-auth/mongo-adapter
@better-auth/oauth-provider
@better-auth/passkey
@better-auth/prisma-adapter
@better-auth/redis-storage
@better-auth/scim
@better-auth/sso
@better-auth/stripe
@better-auth/telemetry
@better-auth/test-utils
commit: |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the cookie parsing utilities to more reliably split combined Set-Cookie header strings (as sometimes surfaced by Fetch/Headers implementations), especially when Expires contains commas and other tricky substrings.
Changes:
- Replace the
splitSetCookieHeaderimplementation with a lookahead heuristic that splits only when a comma is followed by aname=pattern. - Add additional
parseSetCookieHeadertests covering multipleExpiresdate formats and edge cases (e.g.,Expires=0, RFC 850, asctime format).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/better-auth/src/cookies/cookies.test.ts | Adds regression/edge-case tests for parseSetCookieHeader around Expires and mixed cookie lists. |
| packages/better-auth/src/cookies/cookie-utils.ts | Implements new heuristic-based splitting for combined Set-Cookie headers to avoid mis-splitting on Expires commas. |
Comments suppressed due to low confidence (1)
packages/better-auth/src/cookies/cookies.test.ts:282
- The Expires test date string uses a weekday that doesn’t match the calendar date ("Mon, 01 Jan 2026 ..."; 2026-01-01 is a Thursday). Even though parsing may ignore the weekday, keeping it consistent avoids confusing future readers and prevents potential strict parsers from failing; consider changing the weekday (or using an ISO/RFC3339 timestamp) in both the header and expected Date construction.
"a=1; Path=/; HttpOnly, b=2; Expires=Mon, 01 Jan 2026 00:00:00 GMT; Secure, c=3; SameSite=Lax",
);
expect(map.get("a")?.value).toBe("1");
expect(map.get("b")?.value).toBe("2");
expect(map.get("b")?.expires).toEqual(
new Date("Mon, 01 Jan 2026 00:00:00 GMT"),
);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
himself65
approved these changes
Mar 2, 2026
Member
Author
|
-> updating comment |
ping-maxwell
approved these changes
Mar 2, 2026
himself65
pushed a commit
that referenced
this pull request
Mar 3, 2026
5 tasks
himself65
pushed a commit
that referenced
this pull request
Mar 3, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Related to https://discord.com/channels/1288403910284935179/1477776139027087450