[PR #7651] [MERGED] fix: improve Headers detection with instanceof check and cross-realm fallback #24367

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7651
Author: @bytaesu
Created: 1/27/2026
Status: Merged
Merged: 2/3/2026
Merged by: @himself65

Base: canaryHead: 2026-01-28/fix/cookies-headers-check


📝 Commits (5)

  • 26c6482 fix: use instanceof Headers check in getSessionCookie
  • 06a529b test: clean up comment
  • 72c5a97 fix: add duck typing fallback
  • 24b0f6f fix: update getCookieCache as well
  • ec571a4 test: add regression case

📊 Changes

2 files changed (+57 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/cookies/cookies.test.ts (+49 -0)
📝 packages/better-auth/src/cookies/index.ts (+8 -2)

📄 Description

Related to https://github.com/better-auth/better-auth/issues/6853#issuecomment-3690299673

test

Summary by cubic

Update getSessionCookie and getCookieCache to work with native Headers, Next.js ReadonlyHeaders, and cross-realm Headers-like objects. Uses an instanceof check with a duck-typing fallback to reliably read cookies and avoid false positives from prototype-level headers.

  • Bug Fixes
    • Detect Headers with request instanceof Headers or when no headers property; otherwise use request.headers.
    • Apply the same logic to getCookieCache.
    • Added tests for direct Headers, inherited headers on prototype, and cross-realm Headers-like objects.

Written for commit ec571a48f7. 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/7651 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 1/27/2026 **Status:** ✅ Merged **Merged:** 2/3/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `2026-01-28/fix/cookies-headers-check` --- ### 📝 Commits (5) - [`26c6482`](https://github.com/better-auth/better-auth/commit/26c6482e521511e55efa6cd31d061cea0a7f9206) fix: use instanceof Headers check in getSessionCookie - [`06a529b`](https://github.com/better-auth/better-auth/commit/06a529bc6511dcd92e727fa7decdf14becde8a84) test: clean up comment - [`72c5a97`](https://github.com/better-auth/better-auth/commit/72c5a975321f2e783c5ba5d0015f978134199b4b) fix: add duck typing fallback - [`24b0f6f`](https://github.com/better-auth/better-auth/commit/24b0f6f6b3c01554903d5dc991f28cb603b89f9e) fix: update getCookieCache as well - [`ec571a4`](https://github.com/better-auth/better-auth/commit/ec571a48f7dad6c57a06af6bef42e806f8cb583c) test: add regression case ### 📊 Changes **2 files changed** (+57 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/cookies/cookies.test.ts` (+49 -0) 📝 `packages/better-auth/src/cookies/index.ts` (+8 -2) </details> ### 📄 Description Related to https://github.com/better-auth/better-auth/issues/6853#issuecomment-3690299673 <img width="500" alt="test" src="https://github.com/user-attachments/assets/b3558092-8d87-46f6-98ad-785b74134b0b" /> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Update getSessionCookie and getCookieCache to work with native Headers, Next.js ReadonlyHeaders, and cross-realm Headers-like objects. Uses an instanceof check with a duck-typing fallback to reliably read cookies and avoid false positives from prototype-level headers. - **Bug Fixes** - Detect Headers with request instanceof Headers or when no headers property; otherwise use request.headers. - Apply the same logic to getCookieCache. - Added tests for direct Headers, inherited headers on prototype, and cross-realm Headers-like objects. <sup>Written for commit ec571a48f7dad6c57a06af6bef42e806f8cb583c. 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:20:07 -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#24367