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

Closed
opened 2026-04-13 10:32:03 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/8799

State: closed
Merged: No


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/8799 **State:** closed **Merged:** No --- ## 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. -->
GiteaMirror added the pull-request label 2026-04-13 10:32:03 -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#16468