[PR #4530] [MERGED] fix: ignore cookiecache on auth sensitive functions #5430

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4530
Author: @Kinfe123
Created: 9/8/2025
Status: Merged
Merged: 9/9/2025
Merged by: @himself65

Base: canaryHead: fix/sensitive-auth-functions-ignore-cookie-cache


📝 Commits (5)

  • 8140634 fix: tiktok scope
  • cf67489 fix: ignore cookiecache on auth sensitive functions
  • 5673e42 lint
  • 407b0eb lint
  • 166fff1 Merge branch 'canary' into fix/sensitive-auth-functions-ignore-cookie-cache

📊 Changes

3 files changed (+89 additions, -8 deletions)

View changed files

📝 packages/better-auth/src/api/routes/session.ts (+18 -3)
📝 packages/better-auth/src/api/routes/update-user.test.ts (+62 -0)
📝 packages/better-auth/src/api/routes/update-user.ts (+9 -5)

📄 Description

this pr should fix the issue of old session cookies are still cached in browsers . If someone has access to those old devices, they can still use the cached sessions to do on sentitive function with the endpoint - like /change-password


Summary by cubic

Prevents using cached session cookies on sensitive auth actions by forcing fresh session validation. Adds a new middleware and applies it to password, email, deletion, and session revocation endpoints.

  • Bug Fixes

    • Added sensitiveSessionMiddleware that disables cookie cache and requires a valid session.
    • Applied to changePassword, setPassword, changeEmail, deleteUser, revokeSession, revokeSessions, revokeOtherSessions.
    • Added test to confirm cached cookies are ignored after password change.
  • Migration

    • For custom sensitive endpoints, use sensitiveSessionMiddleware instead of sessionMiddleware.

🔄 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/4530 **Author:** [@Kinfe123](https://github.com/Kinfe123) **Created:** 9/8/2025 **Status:** ✅ Merged **Merged:** 9/9/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/sensitive-auth-functions-ignore-cookie-cache` --- ### 📝 Commits (5) - [`8140634`](https://github.com/better-auth/better-auth/commit/81406346de2943d2498446df471fa2502ef0ad47) fix: tiktok scope - [`cf67489`](https://github.com/better-auth/better-auth/commit/cf67489b4ae9b80e2a5baab10ead4167cefa9338) fix: ignore cookiecache on auth sensitive functions - [`5673e42`](https://github.com/better-auth/better-auth/commit/5673e425463ea219e5c9351e963e7f5a9334cf00) lint - [`407b0eb`](https://github.com/better-auth/better-auth/commit/407b0eb2fdd041618876047ddd63b41f206ae3a3) lint - [`166fff1`](https://github.com/better-auth/better-auth/commit/166fff1478b80928d82ab6470b13cc9af3408658) Merge branch 'canary' into fix/sensitive-auth-functions-ignore-cookie-cache ### 📊 Changes **3 files changed** (+89 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/session.ts` (+18 -3) 📝 `packages/better-auth/src/api/routes/update-user.test.ts` (+62 -0) 📝 `packages/better-auth/src/api/routes/update-user.ts` (+9 -5) </details> ### 📄 Description this pr should fix the issue of old session cookies are still cached in browsers . If someone has access to those old devices, they can still use the cached sessions to do on sentitive function with the endpoint - like /change-password <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevents using cached session cookies on sensitive auth actions by forcing fresh session validation. Adds a new middleware and applies it to password, email, deletion, and session revocation endpoints. - **Bug Fixes** - Added sensitiveSessionMiddleware that disables cookie cache and requires a valid session. - Applied to changePassword, setPassword, changeEmail, deleteUser, revokeSession, revokeSessions, revokeOtherSessions. - Added test to confirm cached cookies are ignored after password change. - **Migration** - For custom sensitive endpoints, use sensitiveSessionMiddleware instead of sessionMiddleware. <!-- 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:22:33 -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#5430