[PR #7380] [CLOSED] [backport] fix: preserve attributes when expiring cookies #24172

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7380
Author: @himself65
Created: 1/15/2026
Status: Closed

Base: v1.4.13-stagingHead: v1.4.13-staging-backport-expire-cookie


📝 Commits (1)

  • d8d1773 fix: preserve attributes when expiring cookies (#7363)

📊 Changes

16 files changed (+163 additions, -140 deletions)

View changed files

📝 packages/better-auth/src/api/routes/session.ts (+6 -20)
📝 packages/better-auth/src/context/__snapshots__/create-context.test.ts.snap (+8 -8)
📝 packages/better-auth/src/cookies/cookies.test.ts (+23 -4)
📝 packages/better-auth/src/cookies/index.ts (+30 -32)
📝 packages/better-auth/src/cookies/session-store.ts (+5 -5)
📝 packages/better-auth/src/oauth2/state.ts (+3 -6)
📝 packages/better-auth/src/plugins/admin/routes.ts (+9 -9)
📝 packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts (+25 -1)
📝 packages/better-auth/src/plugins/last-login-method/index.ts (+1 -1)
📝 packages/better-auth/src/plugins/mcp/index.ts (+4 -3)
📝 packages/better-auth/src/plugins/multi-session/index.ts (+19 -15)
📝 packages/better-auth/src/plugins/oidc-provider/index.ts (+8 -13)
📝 packages/better-auth/src/plugins/two-factor/verify-two-factor.ts (+13 -13)
📝 packages/core/src/types/context.ts (+2 -5)
📝 packages/core/src/types/cookie.ts (+6 -4)
📝 packages/core/src/types/index.ts (+1 -1)

📄 Description

Summary by cubic

Backport: ensure cookies expire without losing their attributes (path, domain, sameSite, secure) by introducing a centralized expireCookie helper and applying it across auth flows.

  • Bug Fixes

    • Use expireCookie when clearing session, state, admin, OIDC, MCP, multi-session, two-factor, and account cookies to preserve attributes.
    • OAuth state cookie now expires with correct path and max-age; added tests for this and expireCookie behavior.
    • Preserve __Secure- prefix casing when expiring multi-session cookies.
  • Refactors

    • Standardized cookie shape to BetterAuthCookie and renamed options to attributes.
    • Centralized cookie cleanup in deleteSessionCookie and session-store; updated related tests and helpers.

Written for commit d8d1773914. 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/7380 **Author:** [@himself65](https://github.com/himself65) **Created:** 1/15/2026 **Status:** ❌ Closed **Base:** `v1.4.13-staging` ← **Head:** `v1.4.13-staging-backport-expire-cookie` --- ### 📝 Commits (1) - [`d8d1773`](https://github.com/better-auth/better-auth/commit/d8d17739141fce1eb99df5c76401de6e1c43dde7) fix: preserve attributes when expiring cookies (#7363) ### 📊 Changes **16 files changed** (+163 additions, -140 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/session.ts` (+6 -20) 📝 `packages/better-auth/src/context/__snapshots__/create-context.test.ts.snap` (+8 -8) 📝 `packages/better-auth/src/cookies/cookies.test.ts` (+23 -4) 📝 `packages/better-auth/src/cookies/index.ts` (+30 -32) 📝 `packages/better-auth/src/cookies/session-store.ts` (+5 -5) 📝 `packages/better-auth/src/oauth2/state.ts` (+3 -6) 📝 `packages/better-auth/src/plugins/admin/routes.ts` (+9 -9) 📝 `packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts` (+25 -1) 📝 `packages/better-auth/src/plugins/last-login-method/index.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/mcp/index.ts` (+4 -3) 📝 `packages/better-auth/src/plugins/multi-session/index.ts` (+19 -15) 📝 `packages/better-auth/src/plugins/oidc-provider/index.ts` (+8 -13) 📝 `packages/better-auth/src/plugins/two-factor/verify-two-factor.ts` (+13 -13) 📝 `packages/core/src/types/context.ts` (+2 -5) 📝 `packages/core/src/types/cookie.ts` (+6 -4) 📝 `packages/core/src/types/index.ts` (+1 -1) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Backport: ensure cookies expire without losing their attributes (path, domain, sameSite, secure) by introducing a centralized expireCookie helper and applying it across auth flows. - **Bug Fixes** - Use expireCookie when clearing session, state, admin, OIDC, MCP, multi-session, two-factor, and account cookies to preserve attributes. - OAuth state cookie now expires with correct path and max-age; added tests for this and expireCookie behavior. - Preserve __Secure- prefix casing when expiring multi-session cookies. - **Refactors** - Standardized cookie shape to BetterAuthCookie and renamed options to attributes. - Centralized cookie cleanup in deleteSessionCookie and session-store; updated related tests and helpers. <sup>Written for commit d8d17739141fce1eb99df5c76401de6e1c43dde7. 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:12:51 -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#24172