[PR #7080] [MERGED] fix: filter null values from dynamic trusted origins #15309

Closed
opened 2026-04-13 09:57:29 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: canaryHead: 2026-01-01/fix/filter-null-trusted-origins


📝 Commits (7)

📊 Changes

5 files changed (+81 additions, -25 deletions)

View changed files

📝 packages/better-auth/src/api/middlewares/origin-check.test.ts (+44 -6)
📝 packages/better-auth/src/api/middlewares/origin-check.ts (+3 -1)
📝 packages/better-auth/src/context/create-context.test.ts (+9 -7)
📝 packages/better-auth/src/context/helpers.ts (+7 -10)
📝 packages/core/src/types/init-options.ts (+18 -1)

📄 Description

Summary by cubic

Filter falsy values (null/undefined/empty) from trustedOrigins so origin checks only use valid entries. This prevents false 403s when dynamic headers are missing and keeps CSRF origin validation stable.

  • Bug Fixes

    • Filter falsy entries in getTrustedOrigins and origin-check before merging dynamic origins; stop throwing on invalid entries.
    • Added a test to ensure sign-in succeeds when a valid origin is present alongside null values.
  • Refactors

    • Broaden trustedOrigins types to allow null/undefined in arrays and callback results; added a JSDoc example.

Written for commit 4b304156f2. 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/7080 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 1/1/2026 **Status:** ✅ Merged **Merged:** 1/2/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `2026-01-01/fix/filter-null-trusted-origins` --- ### 📝 Commits (7) - [`eca95d1`](https://github.com/better-auth/better-auth/commit/eca95d15dc83c8d44577347bf3a4641e5cd4854a) fix: filter null values from dynamic trusted origins - [`3a5f91f`](https://github.com/better-auth/better-auth/commit/3a5f91f1fa292b16817679e3c3e679d65fe5fa39) fix: lint - [`277a941`](https://github.com/better-auth/better-auth/commit/277a941d3b28acae4917f318cca373dc5fa2720a) refactor: use Boolean in filter - [`df03ba4`](https://github.com/better-auth/better-auth/commit/df03ba4b8ed53ea71c57361941621149b87cdfa5) docs: update - [`c8a15a7`](https://github.com/better-auth/better-auth/commit/c8a15a7adb355b89c4b84a2f404c8e3f26f85d53) fix: check - [`67b1f3a`](https://github.com/better-auth/better-auth/commit/67b1f3a19ab9bd0ac8a29bb22c09d75c62296947) fix: type - [`4b30415`](https://github.com/better-auth/better-auth/commit/4b304156f2ec56254109a1fca159ed11a7917259) fix: test ### 📊 Changes **5 files changed** (+81 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/middlewares/origin-check.test.ts` (+44 -6) 📝 `packages/better-auth/src/api/middlewares/origin-check.ts` (+3 -1) 📝 `packages/better-auth/src/context/create-context.test.ts` (+9 -7) 📝 `packages/better-auth/src/context/helpers.ts` (+7 -10) 📝 `packages/core/src/types/init-options.ts` (+18 -1) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Filter falsy values (null/undefined/empty) from trustedOrigins so origin checks only use valid entries. This prevents false 403s when dynamic headers are missing and keeps CSRF origin validation stable. - **Bug Fixes** - Filter falsy entries in getTrustedOrigins and origin-check before merging dynamic origins; stop throwing on invalid entries. - Added a test to ensure sign-in succeeds when a valid origin is present alongside null values. - **Refactors** - Broaden trustedOrigins types to allow null/undefined in arrays and callback results; added a JSDoc example. <sup>Written for commit 4b304156f2ec56254109a1fca159ed11a7917259. 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-13 09:57:29 -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#15309