[PR #6720] [CLOSED] fix(cookies): update domain extraction logic for cross-subdomain cookies #23749

Closed
opened 2026-04-15 21:57:10 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6720
Author: @f0wu5u
Created: 12/12/2025
Status: Closed

Base: canaryHead: fix/cross-subdomain-fallback-domain


📝 Commits (1)

  • 4392b62 fix(cookies): update domain extraction logic for cross-subdomain cookies

📊 Changes

2 files changed (+27 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/cookies/cookies.test.ts (+24 -0)
📝 packages/better-auth/src/cookies/index.ts (+3 -1)

📄 Description

This PR extends the fallback domain for crossSubdomain cookies logic to use TLD instead of baseURL hostname;

Issue

Currently when serving better-auth on a subdomain like api.example.com (think of setup like HonoJS/Express API) and client is also on example.com, with crossSubdomain enabled, better-auth redirect to client successfully but client does not have access to cookies because it has .api.example.com as domain.

Fix

This change uses the TLD of the baseURL hostname, in this case example.com so that auth cookies is truly available across all subdomains


Summary by cubic

Fixes cross-subdomain cookies by using the top-level domain from baseURL as the fallback cookie domain, so cookies set on a subdomain are readable on the root domain (e.g., api.example.com -> example.com).

  • Bug Fixes
    • Use baseURL’s top-level domain when crossSubDomainCookies is enabled and no domain is provided.
    • Added a test to assert cookies default to Domain=example.com when baseURL is a subdomain.

Written for commit 4392b62657. Summary will update automatically 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/6720 **Author:** [@f0wu5u](https://github.com/f0wu5u) **Created:** 12/12/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/cross-subdomain-fallback-domain` --- ### 📝 Commits (1) - [`4392b62`](https://github.com/better-auth/better-auth/commit/4392b6265774547268172886bca34ab40e6bdd0a) fix(cookies): update domain extraction logic for cross-subdomain cookies ### 📊 Changes **2 files changed** (+27 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/cookies/cookies.test.ts` (+24 -0) 📝 `packages/better-auth/src/cookies/index.ts` (+3 -1) </details> ### 📄 Description This PR extends the fallback domain for crossSubdomain cookies logic to use TLD instead of baseURL hostname; ### Issue Currently when serving better-auth on a subdomain like `api.example.com` (think of setup like HonoJS/Express API) and client is also on `example.com`, with crossSubdomain enabled, better-auth redirect to client successfully but client does not have access to cookies because it has `.api.example.com` as domain. ### Fix This change uses the TLD of the baseURL hostname, in this case `example.com` so that auth cookies is truly available across all subdomains <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes cross-subdomain cookies by using the top-level domain from baseURL as the fallback cookie domain, so cookies set on a subdomain are readable on the root domain (e.g., api.example.com -> example.com). - **Bug Fixes** - Use baseURL’s top-level domain when crossSubDomainCookies is enabled and no domain is provided. - Added a test to assert cookies default to Domain=example.com when baseURL is a subdomain. <sup>Written for commit 4392b6265774547268172886bca34ab40e6bdd0a. Summary will update automatically 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 21:57:10 -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#23749