[PR #7370] [CLOSED] fix(cookie): relaxes cookie retrieval for getSessionCookie #7266

Closed
opened 2026-03-13 13:30:08 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7370
Author: @tomsiwik
Created: 1/14/2026
Status: Closed

Base: canaryHead: fix/cookiePrefix-cookieName-handling


📝 Commits (6)

  • c981531 fix(better-auth/cookie): relaxes cookie retrieval for dot/dash delimiters
  • 2795f79 fix: restore secure cookie test
  • 5233873 test: adds additional secure prefix tests and considers '.' priority
  • 84822a5 Merge branch 'canary' into fix/cookiePrefix-cookieName-handling
  • 263c119 Merge branch 'canary' into fix/cookiePrefix-cookieName-handling
  • f62a389 Merge branch 'canary' into fix/cookiePrefix-cookieName-handling

📊 Changes

2 files changed (+35 additions, -16 deletions)

View changed files

📝 packages/better-auth/src/cookies/cookies.test.ts (+24 -1)
📝 packages/better-auth/src/cookies/index.ts (+11 -15)

📄 Description

Default cookie set up via createCookie when providing prefix and cookieName is:

a1e14adb61/packages/better-auth/src/cookies/index.ts (L55)

but getSessionCookie assumes - as delimiter when providing cookiePrefix and cookieName.
a1e14adb61/packages/better-auth/src/cookies/index.ts (L373)

Untested side-effects added to test suite for default, secure cookie prefix and combinations


Summary by cubic

Fixes session cookie retrieval to handle both "." and "-" separators between cookiePrefix and cookieName, including secure cookies. Prevents missing sessions when cookies use the dot format from createCookie.

  • Bug Fixes
    • getSessionCookie now checks prefix-cookieName and prefix.cookieName (secure variants), preferring the dot form.
    • Stops mutating config.cookiePrefix; uses the provided prefix as-is.
    • Adds parameterized tests for default/custom prefix and name combinations.

Written for commit f62a3897c3. 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/7370 **Author:** [@tomsiwik](https://github.com/tomsiwik) **Created:** 1/14/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/cookiePrefix-cookieName-handling` --- ### 📝 Commits (6) - [`c981531`](https://github.com/better-auth/better-auth/commit/c981531390bd30173bef4843a13be37c99f0623d) fix(better-auth/cookie): relaxes cookie retrieval for dot/dash delimiters - [`2795f79`](https://github.com/better-auth/better-auth/commit/2795f793eef38639b2fd89d1fbc4d27948cfba82) fix: restore secure cookie test - [`5233873`](https://github.com/better-auth/better-auth/commit/523387384f4ca3af6f98df9bb973c4d1e2072dae) test: adds additional secure prefix tests and considers '.' priority - [`84822a5`](https://github.com/better-auth/better-auth/commit/84822a519b8c788c3e5c58b9cdbc999d8f68e09a) Merge branch 'canary' into fix/cookiePrefix-cookieName-handling - [`263c119`](https://github.com/better-auth/better-auth/commit/263c119e59253020ebdfdb0b7190ca664ffaa4c5) Merge branch 'canary' into fix/cookiePrefix-cookieName-handling - [`f62a389`](https://github.com/better-auth/better-auth/commit/f62a3897c3894dd6faa6185b8c2fe6b584410dfb) Merge branch 'canary' into fix/cookiePrefix-cookieName-handling ### 📊 Changes **2 files changed** (+35 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/cookies/cookies.test.ts` (+24 -1) 📝 `packages/better-auth/src/cookies/index.ts` (+11 -15) </details> ### 📄 Description Default cookie set up via `createCookie` when providing `prefix` and `cookieName` is: https://github.com/better-auth/better-auth/blob/a1e14adb61888a50a215701a4708b154990201cf/packages/better-auth/src/cookies/index.ts#L55 but `getSessionCookie` assumes `-` as delimiter when providing `cookiePrefix` and `cookieName`. https://github.com/better-auth/better-auth/blob/a1e14adb61888a50a215701a4708b154990201cf/packages/better-auth/src/cookies/index.ts#L373 Untested side-effects added to test suite for default, secure cookie prefix and combinations <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes session cookie retrieval to handle both "." and "-" separators between cookiePrefix and cookieName, including secure cookies. Prevents missing sessions when cookies use the dot format from createCookie. - **Bug Fixes** - getSessionCookie now checks prefix-cookieName and prefix.cookieName (secure variants), preferring the dot form. - Stops mutating config.cookiePrefix; uses the provided prefix as-is. - Adds parameterized tests for default/custom prefix and name combinations. <sup>Written for commit f62a3897c3894dd6faa6185b8c2fe6b584410dfb. 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-03-13 13:30:08 -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#7266