[PR #3283] [MERGED] fix: use same expires at date for cookie session data payload and signature #21635

Closed
opened 2026-04-15 20:30:35 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3283
Author: @PacifismPostMortem
Created: 7/6/2025
Status: Merged
Merged: 7/26/2025
Merged by: @Bekacru

Base: mainHead: cookie-cache


📝 Commits (2)

  • ad9fab6 fix: use same expires at date for cookie session data payload and signature
  • 1c0439e chore: lint

📊 Changes

1 file changed (+6 additions, -8 deletions)

View changed files

📝 packages/better-auth/src/cookies/index.ts (+6 -8)

📄 Description

With cookie cache enabled, getSession was sporadically returning null and clearing the session data cookie. The problem is setCookeCache generates two expiresAt times, once for the session data and another when signing the payload of the cookie, instead of using the same value. When testing, the values were sometimes identical, and other times 1 tick off, which resulted in getSession sometimes returning null and clearing the cookies. The fix was to generate one expiresAt time so the signature is signing the same data as the session data.


🔄 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/3283 **Author:** [@PacifismPostMortem](https://github.com/PacifismPostMortem) **Created:** 7/6/2025 **Status:** ✅ Merged **Merged:** 7/26/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `cookie-cache` --- ### 📝 Commits (2) - [`ad9fab6`](https://github.com/better-auth/better-auth/commit/ad9fab6a0b0dada618e8832e8897fc87deb5230e) fix: use same expires at date for cookie session data payload and signature - [`1c0439e`](https://github.com/better-auth/better-auth/commit/1c0439e7c3d6958cadd16cd3519b550a61bb11b4) chore: lint ### 📊 Changes **1 file changed** (+6 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/cookies/index.ts` (+6 -8) </details> ### 📄 Description With cookie cache enabled, getSession was sporadically returning null and clearing the session data cookie. The problem is [setCookeCache](https://github.com/better-auth/better-auth/blob/2de1cd27f6177de7e18e57391eb1a0c5dc1cdda3/packages/better-auth/src/cookies/index.ts#L124) generates two expiresAt times, once for the session data and another when signing the payload of the cookie, instead of using the same value. When testing, the values were sometimes identical, and other times 1 tick off, which resulted in [getSession](https://github.com/better-auth/better-auth/blob/b98d17720e6fa642090a88bd8c6a0997647a9275/packages/better-auth/src/api/routes/session.ts#L109) sometimes returning null and clearing the cookies. The fix was to generate one expiresAt time so the signature is signing the same data as the session data. --- <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 20:30:35 -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#21635