[PR #8799] [CLOSED] fix(next): prevent empty __better-auth-cookie-store cookie leak #25122

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8799
Author: @cyphercodes
Created: 3/27/2026
Status: Closed

Base: mainHead: fix/next-cookies-internal-cookie-leak


📝 Commits (1)

  • 45fa12c fix(next): remove cookieStore.delete() to prevent empty cookie leak

📊 Changes

1 file changed (+4 additions, -3 deletions)

View changed files

📝 packages/better-auth/src/integrations/next-js.ts (+4 -3)

📄 Description

Summary

The nextCookies plugin was leaking an empty __better-auth-cookie-store cookie to clients because cookieStore.delete() in Next.js only sets the cookie value to empty without removing the key from the internal map.

Changes

  • Removed the cookieStore.delete() call after setting the test cookie
  • The test cookie uses maxAge: 0 so it expires immediately anyway
  • Server Component detection still works via try/catch on set()

Issue

Fixes #8784


Summary by cubic

Stop leaking an empty __better-auth-cookie-store cookie in Next.js by removing cookieStore.delete() in the nextCookies plugin. The test cookie now expires with maxAge: 0 and is renamed to __better_auth_sc_test; Server Component detection still uses try/catch on set, fixing #8784.

Written for commit 45fa12cdad. 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/8799 **Author:** [@cyphercodes](https://github.com/cyphercodes) **Created:** 3/27/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/next-cookies-internal-cookie-leak` --- ### 📝 Commits (1) - [`45fa12c`](https://github.com/better-auth/better-auth/commit/45fa12cdad9059dee75f56767332d68304cee2d6) fix(next): remove cookieStore.delete() to prevent empty cookie leak ### 📊 Changes **1 file changed** (+4 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/integrations/next-js.ts` (+4 -3) </details> ### 📄 Description ## Summary The `nextCookies` plugin was leaking an empty `__better-auth-cookie-store` cookie to clients because `cookieStore.delete()` in Next.js only sets the cookie value to empty without removing the key from the internal map. ## Changes - Removed the `cookieStore.delete()` call after setting the test cookie - The test cookie uses `maxAge: 0` so it expires immediately anyway - Server Component detection still works via try/catch on `set()` ## Issue Fixes #8784 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Stop leaking an empty `__better-auth-cookie-store` cookie in Next.js by removing cookieStore.delete() in the `nextCookies` plugin. The test cookie now expires with maxAge: 0 and is renamed to `__better_auth_sc_test`; Server Component detection still uses try/catch on set, fixing #8784. <sup>Written for commit 45fa12cdad9059dee75f56767332d68304cee2d6. 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:43:55 -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#25122