[PR #6285] [MERGED] feat: add support for trusted proxy headers in base URL inference #6568

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6285
Author: @Bekacru
Created: 11/25/2025
Status: Merged
Merged: 11/26/2025
Merged by: @Bekacru

Base: canaryHead: fix/proxy


📝 Commits (6)

  • 9a7c6ec feat: add support for trusted proxy headers in base URL inference
  • b1b7086 Apply suggestions from code review
  • 4295e26 chore: lint
  • bcd1ec5 Merge branch 'canary' into fix/proxy
  • 5b54dec Merge branch 'canary' into fix/proxy
  • eab8dd5 Merge branch 'canary' into fix/proxy

📊 Changes

4 files changed (+88 additions, -4 deletions)

View changed files

📝 packages/better-auth/src/auth/auth.test.ts (+64 -2)
📝 packages/better-auth/src/auth/base.ts (+8 -1)
📝 packages/better-auth/src/utils/url.ts (+2 -1)
📝 packages/core/src/types/init-options.ts (+14 -0)

📄 Description

Summary by cubic

Adds an option to trust proxy headers when inferring the base URL. By default, we no longer use X-Forwarded-* headers, which reduces spoofing risk.

  • New Features

    • Added advanced.trustedProxyHeaders (boolean). When true and no BASE_URL/baseURL is set, base URL is inferred from x-forwarded-host and x-forwarded-proto.
    • Added tests for trusted vs. untrusted proxy header behavior.
  • Migration

    • If your app relies on X-Forwarded-* to set the base URL behind a proxy, enable advanced.trustedProxyHeaders: true or set BASE_URL/baseURL explicitly.

Written for commit eab8dd54f8. 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/6285 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 11/25/2025 **Status:** ✅ Merged **Merged:** 11/26/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/proxy` --- ### 📝 Commits (6) - [`9a7c6ec`](https://github.com/better-auth/better-auth/commit/9a7c6eccd6430496ec825c72f289f7d489ffa1d9) feat: add support for trusted proxy headers in base URL inference - [`b1b7086`](https://github.com/better-auth/better-auth/commit/b1b7086325f0d8f9958251622e71193fdea20fd4) Apply suggestions from code review - [`4295e26`](https://github.com/better-auth/better-auth/commit/4295e26d46f2b9b639ac19f9b6cb1b98b9a77aed) chore: lint - [`bcd1ec5`](https://github.com/better-auth/better-auth/commit/bcd1ec5b0b9705ae1772d92730b0ab2ad654d528) Merge branch 'canary' into fix/proxy - [`5b54dec`](https://github.com/better-auth/better-auth/commit/5b54dec01779227fe0c2d4b41c561063fccab1af) Merge branch 'canary' into fix/proxy - [`eab8dd5`](https://github.com/better-auth/better-auth/commit/eab8dd54f8da19edb779b775d0c2bec20e5dcb42) Merge branch 'canary' into fix/proxy ### 📊 Changes **4 files changed** (+88 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/auth/auth.test.ts` (+64 -2) 📝 `packages/better-auth/src/auth/base.ts` (+8 -1) 📝 `packages/better-auth/src/utils/url.ts` (+2 -1) 📝 `packages/core/src/types/init-options.ts` (+14 -0) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds an option to trust proxy headers when inferring the base URL. By default, we no longer use X-Forwarded-* headers, which reduces spoofing risk. - **New Features** - Added advanced.trustedProxyHeaders (boolean). When true and no BASE_URL/baseURL is set, base URL is inferred from x-forwarded-host and x-forwarded-proto. - Added tests for trusted vs. untrusted proxy header behavior. - **Migration** - If your app relies on X-Forwarded-* to set the base URL behind a proxy, enable advanced.trustedProxyHeaders: true or set BASE_URL/baseURL explicitly. <sup>Written for commit eab8dd54f8da19edb779b775d0c2bec20e5dcb42. 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-03-13 13:03:35 -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#6568