Skip to content

fix(cookies): use lookahead heuristic for splitting Set-Cookie headers#8301

Merged
Bekacru merged 4 commits intocanaryfrom
2026-03-03/fix/split-set-cookie-header
Mar 2, 2026
Merged

fix(cookies): use lookahead heuristic for splitting Set-Cookie headers#8301
Bekacru merged 4 commits intocanaryfrom
2026-03-03/fix/split-set-cookie-header

Conversation

@bytaesu
Copy link
Copy Markdown
Member

@bytaesu bytaesu commented Mar 2, 2026

Copilot AI review requested due to automatic review settings March 2, 2026 20:36
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
better-auth-demo Ignored Ignored Mar 2, 2026 8:44pm
better-auth-docs Skipped Skipped Mar 2, 2026 8:44pm

Request Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 2, 2026

Open in StackBlitz

@better-auth/api-key

npm i https://pkg.pr.new/@better-auth/api-key@8301

better-auth

npm i https://pkg.pr.new/better-auth@8301

auth

npm i https://pkg.pr.new/auth@8301

@better-auth/core

npm i https://pkg.pr.new/@better-auth/core@8301

@better-auth/drizzle-adapter

npm i https://pkg.pr.new/@better-auth/drizzle-adapter@8301

@better-auth/electron

npm i https://pkg.pr.new/@better-auth/electron@8301

@better-auth/expo

npm i https://pkg.pr.new/@better-auth/expo@8301

@better-auth/i18n

npm i https://pkg.pr.new/@better-auth/i18n@8301

@better-auth/kysely-adapter

npm i https://pkg.pr.new/@better-auth/kysely-adapter@8301

@better-auth/memory-adapter

npm i https://pkg.pr.new/@better-auth/memory-adapter@8301

@better-auth/mongo-adapter

npm i https://pkg.pr.new/@better-auth/mongo-adapter@8301

@better-auth/oauth-provider

npm i https://pkg.pr.new/@better-auth/oauth-provider@8301

@better-auth/passkey

npm i https://pkg.pr.new/@better-auth/passkey@8301

@better-auth/prisma-adapter

npm i https://pkg.pr.new/@better-auth/prisma-adapter@8301

@better-auth/redis-storage

npm i https://pkg.pr.new/@better-auth/redis-storage@8301

@better-auth/scim

npm i https://pkg.pr.new/@better-auth/scim@8301

@better-auth/sso

npm i https://pkg.pr.new/@better-auth/sso@8301

@better-auth/stripe

npm i https://pkg.pr.new/@better-auth/stripe@8301

@better-auth/telemetry

npm i https://pkg.pr.new/@better-auth/telemetry@8301

@better-auth/test-utils

npm i https://pkg.pr.new/@better-auth/test-utils@8301

commit: 183ab2c

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 splitSetCookieHeader implementation with a lookahead heuristic that splits only when a comma is followed by a name= pattern.
  • Add additional parseSetCookieHeader tests covering multiple Expires date 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.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@vercel vercel bot temporarily deployed to Preview – better-auth-docs March 2, 2026 20:40 Inactive
@bytaesu bytaesu marked this pull request as draft March 2, 2026 20:41
@bytaesu
Copy link
Copy Markdown
Member Author

bytaesu commented Mar 2, 2026

-> updating comment

@vercel vercel bot temporarily deployed to Preview – better-auth-docs March 2, 2026 20:42 Inactive
@bytaesu bytaesu marked this pull request as ready for review March 2, 2026 20:42
@vercel vercel bot temporarily deployed to Preview – better-auth-docs March 2, 2026 20:44 Inactive
@bytaesu bytaesu added the ready PR is ready to merge label Mar 2, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@Bekacru Bekacru merged commit add7b2b into canary Mar 2, 2026
25 checks passed
@better-auth better-auth locked as resolved and limited conversation to collaborators Apr 1, 2026
@bytaesu bytaesu added the locked Locked conversations after being closed for 7 days label Apr 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked Locked conversations after being closed for 7 days ready PR is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants