[PR #6882] [MERGED] fix(auth): respect trustedOrigins when baseURL is inferred #6941

Closed
opened 2026-03-13 13:18:03 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6882
Author: @Paola3stefania
Created: 12/19/2025
Status: Merged
Merged: 12/19/2025
Merged by: @Bekacru

Base: canaryHead: fix/trusted-origins-inferred-baseurl


📝 Commits (2)

📊 Changes

3 files changed (+97 additions, -6 deletions)

View changed files

📝 docs/content/docs/reference/options.mdx (+5 -1)
📝 packages/better-auth/src/api/middlewares/origin-check.test.ts (+90 -4)
📝 packages/better-auth/src/auth/base.ts (+2 -1)

📄 Description

Summary by cubic

Fixes origin checks to honor trustedOrigins when baseURL is inferred from the first request, preventing false “Invalid origin” errors. Config arrays and BETTER_AUTH_TRUSTED_ORIGINS are now respected even without a configured baseURL.

  • Bug Fixes

    • Rebuilds trustedOrigins after inferring baseURL, adding the inferred origin, config array entries, and BETTER_AUTH_TRUSTED_ORIGINS.
    • Keeps function-based trustedOrigins working at request time.
    • Adds regression tests covering trusted config/env origins, rejection of untrusted origins, and acceptance of the inferred baseURL origin.
  • Docs

    • Corrects env var name to BETTER_AUTH_URL.
    • Adds a warning recommending explicit baseURL configuration for security and stability.

Written for commit 7740192692. Summary will update automatically on new commits.

fixes https://github.com/better-auth/better-auth/issues/6798


🔄 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/6882 **Author:** [@Paola3stefania](https://github.com/Paola3stefania) **Created:** 12/19/2025 **Status:** ✅ Merged **Merged:** 12/19/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/trusted-origins-inferred-baseurl` --- ### 📝 Commits (2) - [`ea85f40`](https://github.com/better-auth/better-auth/commit/ea85f40589791140f2f89b0ca4de3735cd398a97) fix: infer base url - [`7740192`](https://github.com/better-auth/better-auth/commit/77401926927b2fc902cafda5de889813b9cbbbf5) fix: clean up ### 📊 Changes **3 files changed** (+97 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/reference/options.mdx` (+5 -1) 📝 `packages/better-auth/src/api/middlewares/origin-check.test.ts` (+90 -4) 📝 `packages/better-auth/src/auth/base.ts` (+2 -1) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Fixes origin checks to honor trustedOrigins when baseURL is inferred from the first request, preventing false “Invalid origin” errors. Config arrays and BETTER_AUTH_TRUSTED_ORIGINS are now respected even without a configured baseURL. - **Bug Fixes** - Rebuilds trustedOrigins after inferring baseURL, adding the inferred origin, config array entries, and BETTER_AUTH_TRUSTED_ORIGINS. - Keeps function-based trustedOrigins working at request time. - Adds regression tests covering trusted config/env origins, rejection of untrusted origins, and acceptance of the inferred baseURL origin. - **Docs** - Corrects env var name to BETTER_AUTH_URL. - Adds a warning recommending explicit baseURL configuration for security and stability. <sup>Written for commit 77401926927b2fc902cafda5de889813b9cbbbf5. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> fixes https://github.com/better-auth/better-auth/issues/6798 --- <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-03-13 13:18: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#6941