[PR #4482] feat: support cross-domain cookie #5404

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

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

State: closed
Merged: Yes


This PR is based on the excellent work done by @RikhiSingh in PR #3030
.
The implementation itself was already correct, but the related documentation contained some inconsistencies.

In this PR I’ve:

Kept the original implementation exactly as it was.

Fixed and clarified the documentation so it matches the behavior correctly.

All credits for the actual fix and implementation go to @RikhiSingh. I’ve only adjusted the docs to help get this merged and make it easier for others to use.

Note to maintainers:
Could you please review and validate this PR? Since the core logic was already resolved in the original contribution, this only aligns the docs with the actual behavior. Getting this merged would help the community move forward with a consistent reference. 🙏 @Bekacru @himself65 @Kinfe123

Fixes #2962


Summary by cubic

Add cross-origin cookie support and enforce SameSite=None + Secure rules. Updates docs and tests to make cross-domain and subdomain setups safe and straightforward.

  • New Features

    • advanced.crossOriginCookies with enabled, autoSecure (default true), and allowLocalhostUnsecure (default true).
    • Auto-sets Secure for SameSite=None (skips on localhost when allowed); supports Partitioned cookies.
    • Clear docs for cross-domain vs. cross-subdomain cookies, with examples, CORS/credentials guidance, and trustedOrigins usage.
  • Bug Fixes

    • Throws when SameSite=None is used without Secure on non-localhost.
    • Applies __Secure- cookie prefix based on final merged attributes.
    • Merges defaultCookieAttributes and overrides correctly; adds tests covering all cases.
**Original Pull Request:** https://github.com/better-auth/better-auth/pull/4482 **State:** closed **Merged:** Yes --- This PR is based on the excellent work done by @RikhiSingh in PR #3030 . The implementation itself was already correct, but the related documentation contained some inconsistencies. In this PR I’ve: Kept the original implementation exactly as it was. Fixed and clarified the documentation so it matches the behavior correctly. All credits for the actual fix and implementation go to @RikhiSingh. I’ve only adjusted the docs to help get this merged and make it easier for others to use. Note to maintainers: Could you please review and validate this PR? Since the core logic was already resolved in the original contribution, this only aligns the docs with the actual behavior. Getting this merged would help the community move forward with a consistent reference. 🙏 @Bekacru @himself65 @Kinfe123 Fixes #2962 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add cross-origin cookie support and enforce SameSite=None + Secure rules. Updates docs and tests to make cross-domain and subdomain setups safe and straightforward. - **New Features** - advanced.crossOriginCookies with enabled, autoSecure (default true), and allowLocalhostUnsecure (default true). - Auto-sets Secure for SameSite=None (skips on localhost when allowed); supports Partitioned cookies. - Clear docs for cross-domain vs. cross-subdomain cookies, with examples, CORS/credentials guidance, and trustedOrigins usage. - **Bug Fixes** - Throws when SameSite=None is used without Secure on non-localhost. - Applies __Secure- cookie prefix based on final merged attributes. - Merges defaultCookieAttributes and overrides correctly; adds tests covering all cases. <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-03-13 12:21:43 -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#5404