[PR #8817] fix(session): preserve real session expiry during stateless cache refresh #25134

Open
opened 2026-04-15 22:44:09 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8817
Author: @cyphercodes
Created: 3/28/2026
Status: 🔄 Open

Base: mainHead: fix/session-expiresAt-cookie-cache


📝 Commits (1)

  • e8da9e5 fix(session): preserve real session expiry during stateless cache refresh

📊 Changes

1 file changed (+0 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/api/routes/session.ts (+0 -2)

📄 Description

Description

Fixes #8770

When cookieCache.refreshCache is enabled (stateless mode), the get-session endpoint was incorrectly overwriting session.session.expiresAt with now + cookieCache.maxAge instead of preserving the real session expiry.

Root Cause

In the stateless cache refresh path, refreshedSession was overriding expiresAt with the cookie cache TTL:

const newExpiresAt = getDate(cookieMaxAge, "sec");
const refreshedSession = {
  session: {
    ...session.session,
    expiresAt: newExpiresAt, // ← overwrites real session expiry with cache TTL
  },
  ...
};

Fix

Remove the expiresAt: newExpiresAt override. The spread ...session.session already carries the real expiresAt, and setCookieCache sets the JWE cookie expiration independently from authCookies.sessionData.attributes.maxAge.

Changes

  • Removed newExpiresAt variable
  • Removed expiresAt: newExpiresAt from refreshedSession

Summary by cubic

Preserves the real session expiration when cookieCache.refreshCache is enabled by removing the incorrect expiresAt override in the get-session refresh path. Prevents long‑lived sessions from being shortened to the cookie cache TTL; fixes #8770.

Written for commit e8da9e5aad. 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/8817 **Author:** [@cyphercodes](https://github.com/cyphercodes) **Created:** 3/28/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/session-expiresAt-cookie-cache` --- ### 📝 Commits (1) - [`e8da9e5`](https://github.com/better-auth/better-auth/commit/e8da9e5aadaec89a36e3d8d14417292d1d829bac) fix(session): preserve real session expiry during stateless cache refresh ### 📊 Changes **1 file changed** (+0 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/session.ts` (+0 -2) </details> ### 📄 Description ## Description Fixes #8770 When `cookieCache.refreshCache` is enabled (stateless mode), the get-session endpoint was incorrectly overwriting `session.session.expiresAt` with `now + cookieCache.maxAge` instead of preserving the real session expiry. ### Root Cause In the stateless cache refresh path, `refreshedSession` was overriding `expiresAt` with the cookie cache TTL: ```typescript const newExpiresAt = getDate(cookieMaxAge, "sec"); const refreshedSession = { session: { ...session.session, expiresAt: newExpiresAt, // ← overwrites real session expiry with cache TTL }, ... }; ``` ### Fix Remove the `expiresAt: newExpiresAt` override. The spread `...session.session` already carries the real `expiresAt`, and `setCookieCache` sets the JWE cookie expiration independently from `authCookies.sessionData.attributes.maxAge`. ### Changes - Removed `newExpiresAt` variable - Removed `expiresAt: newExpiresAt` from `refreshedSession` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Preserves the real session expiration when `cookieCache.refreshCache` is enabled by removing the incorrect `expiresAt` override in the get-session refresh path. Prevents long‑lived sessions from being shortened to the cookie cache TTL; fixes #8770. <sup>Written for commit e8da9e5aadaec89a36e3d8d14417292d1d829bac. 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:44:09 -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#25134