[PR #4388] [MERGED] fix(custom-session): don't overwrite the Set-Cookie header #5352

Closed
opened 2026-03-13 12:19:55 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4388
Author: @frectonz
Created: 9/3/2025
Status: Merged
Merged: 9/25/2025
Merged by: @himself65

Base: canaryHead: fix/set-cookie-header-getting-overwritten-in-custom-session


📝 Commits (2)

  • 316ca70 fix(custom-session): handle set cookie call separately so that it won't get overwritten
  • 6d921a6 test(custom-session): test that cookies are set properly

📊 Changes

2 files changed (+22 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/plugins/custom-session/custom-session.test.ts (+15 -1)
📝 packages/better-auth/src/plugins/custom-session/index.ts (+7 -0)

📄 Description

closes #3713

The set-cookie header was being overwritten meaning that even though getSession sets two cookies when cookie cache is enabled, namely better-auth.session_token and better-auth.session_data, the setHeader call overwrites the headers so that only better-auth.session_data is actually sent off to the user.


Summary by cubic

Fixes #3713: Preserve multiple Set-Cookie headers in customSession so both better-auth.session_token and better-auth.session_data are sent when cookie caching is enabled.

  • Bug Fixes
    • Handle Set-Cookie separately before copying other headers to prevent overwrite.
    • Remove Set-Cookie from the session header map after forwarding to avoid duplication.

🔄 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/4388 **Author:** [@frectonz](https://github.com/frectonz) **Created:** 9/3/2025 **Status:** ✅ Merged **Merged:** 9/25/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/set-cookie-header-getting-overwritten-in-custom-session` --- ### 📝 Commits (2) - [`316ca70`](https://github.com/better-auth/better-auth/commit/316ca70638224d7ef0b6f67b940e9ccec6b2a28a) fix(custom-session): handle set cookie call separately so that it won't get overwritten - [`6d921a6`](https://github.com/better-auth/better-auth/commit/6d921a6e2f50f140f1cb630908acf568d3eee2a7) test(custom-session): test that cookies are set properly ### 📊 Changes **2 files changed** (+22 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/custom-session/custom-session.test.ts` (+15 -1) 📝 `packages/better-auth/src/plugins/custom-session/index.ts` (+7 -0) </details> ### 📄 Description closes #3713 The `set-cookie` header was being overwritten meaning that even though `getSession` sets two cookies when cookie cache is enabled, namely `better-auth.session_token` and `better-auth.session_data`, the `setHeader` call overwrites the headers so that only `better-auth.session_data` is actually sent off to the user. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes #3713: Preserve multiple Set-Cookie headers in customSession so both better-auth.session_token and better-auth.session_data are sent when cookie caching is enabled. - **Bug Fixes** - Handle Set-Cookie separately before copying other headers to prevent overwrite. - Remove Set-Cookie from the session header map after forwarding to avoid duplication. <!-- 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-03-13 12:19:55 -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#5352