[PR #7879] [MERGED] fix(custom-session): use getSetCookie() to preserve individual Set-Cookie headers #24509

Closed
opened 2026-04-15 22:24:21 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7879
Author: @thomaspeklak
Created: 2/9/2026
Status: Merged
Merged: 2/15/2026
Merged by: @Bekacru

Base: canaryHead: fix/custom-session-set-cookie-headers


📝 Commits (2)

  • d693fcf fix(custom-session): use getSetCookie() to preserve individual Set-Cookie headers
  • 2fb5437 Merge branch 'canary' into fix/custom-session-set-cookie-headers

📊 Changes

2 files changed (+124 additions, -12 deletions)

View changed files

📝 packages/better-auth/src/plugins/custom-session/custom-session.test.ts (+109 -8)
📝 packages/better-auth/src/plugins/custom-session/index.ts (+15 -4)

📄 Description

Fixes #7878

Summary

  • Replace Headers.get("set-cookie") with Headers.getSetCookie() to avoid comma-joining multiple Set-Cookie values
  • Use Headers.append() instead of Headers.set() to preserve each cookie as a separate response header
  • Add regression tests verifying individual cookie Max-Age values are preserved when cookieCache is enabled

Test plan

  • Existing tests updated and passing
  • New test: verifies session_token and session_data retain their own Max-Age when expiresIn and cookieCache.maxAge differ
  • New test: verifies no single Set-Cookie entry contains multiple better-auth.* cookies (no comma-joining)
  • pnpm lint clean
  • pnpm typecheck clean

Summary by cubic

Preserves individual Set-Cookie headers in the custom-session plugin to prevent attribute merging. Fixes premature session expiry when cookieCache is enabled.

  • Bug Fixes
    • Use Headers.getSetCookie(), parse each cookie, set via ctx.setCookie(...), then delete the original Set-Cookie header to avoid merging.
    • Add tests for separate Set-Cookie entries, preserved distinct Max-Age for session_token vs session_data with cookieCache, and no comma-joining.

Written for commit 2fb5437c50. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7879 **Author:** [@thomaspeklak](https://github.com/thomaspeklak) **Created:** 2/9/2026 **Status:** ✅ Merged **Merged:** 2/15/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/custom-session-set-cookie-headers` --- ### 📝 Commits (2) - [`d693fcf`](https://github.com/better-auth/better-auth/commit/d693fcf731895626530c54b54fdbff66357da85d) fix(custom-session): use getSetCookie() to preserve individual Set-Cookie headers - [`2fb5437`](https://github.com/better-auth/better-auth/commit/2fb5437c50576b189fa13fa5acd2c248b5653a7e) Merge branch 'canary' into fix/custom-session-set-cookie-headers ### 📊 Changes **2 files changed** (+124 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/custom-session/custom-session.test.ts` (+109 -8) 📝 `packages/better-auth/src/plugins/custom-session/index.ts` (+15 -4) </details> ### 📄 Description Fixes #7878 ## Summary * Replace `Headers.get("set-cookie")` with `Headers.getSetCookie()` to avoid comma-joining multiple Set-Cookie values * Use `Headers.append()` instead of `Headers.set()` to preserve each cookie as a separate response header * Add regression tests verifying individual cookie Max-Age values are preserved when `cookieCache` is enabled ## Test plan - [x] Existing tests updated and passing - [x] New test: verifies `session_token` and `session_data` retain their own `Max-Age` when `expiresIn` and `cookieCache.maxAge` differ - [x] New test: verifies no single `Set-Cookie` entry contains multiple `better-auth.*` cookies (no comma-joining) - [x] `pnpm lint` clean - [x] `pnpm typecheck` clean <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Preserves individual Set-Cookie headers in the custom-session plugin to prevent attribute merging. Fixes premature session expiry when cookieCache is enabled. - **Bug Fixes** - Use Headers.getSetCookie(), parse each cookie, set via ctx.setCookie(...), then delete the original Set-Cookie header to avoid merging. - Add tests for separate Set-Cookie entries, preserved distinct Max-Age for session_token vs session_data with cookieCache, and no comma-joining. <sup>Written for commit 2fb5437c50576b189fa13fa5acd2c248b5653a7e. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:24:21 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#24509