[PR #7204] [MERGED] fix(core): separate CSRF and origin checks #15390

Closed
opened 2026-04-13 10:00:30 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7204
Author: @Paola3stefania
Created: 1/8/2026
Status: Merged
Merged: 1/11/2026
Merged by: @himself65

Base: canaryHead: fix/separate-csrf-and-origin-checks


📝 Commits (10+)

  • cb48766 feat: separate disableCSRFCheck and disableOriginCheck
  • c0f2178 feat: add backward compat
  • 51863b2 Merge branch 'canary' into fix/separate-csrf-and-origin-checks
  • 13cb150 refactor
  • 409f413 fix test
  • 444fd65 docs: add default
  • 9fff796 fix: lint
  • 641846a fix: deprecate
  • fb84114 Merge branch 'canary' into fix/separate-csrf-and-origin-checks
  • 888c124 fix: test

📊 Changes

10 files changed (+365 additions, -17 deletions)

View changed files

📝 docs/content/docs/reference/options.mdx (+2 -2)
📝 docs/content/docs/reference/security.mdx (+33 -3)
📝 packages/better-auth/src/api/middlewares/origin-check.test.ts (+224 -0)
📝 packages/better-auth/src/api/middlewares/origin-check.ts (+50 -3)
📝 packages/better-auth/src/api/routes/sign-in.test.ts (+11 -1)
📝 packages/better-auth/src/api/routes/sign-up.test.ts (+6 -0)
📝 packages/better-auth/src/cookies/cookies.test.ts (+14 -4)
📝 packages/better-auth/src/plugins/magic-link/magic-link.test.ts (+3 -0)
📝 packages/better-auth/src/social.test.ts (+3 -0)
📝 packages/core/src/types/init-options.ts (+19 -4)

📄 Description

Summary by cubic

Separated CSRF protection from origin URL validation to give precise control over security and prevent misconfiguration. Flags now target one area each, with backward compatibility for existing disableOriginCheck setups.

  • Bug Fixes
    • CSRF check now controls origin header validation and Fetch Metadata protections.
    • Origin check only validates redirect-related URLs (callbackURL, redirectTo, etc.).
    • Middleware honors skipCSRFCheck and skipOriginCheck independently.
    • disableOriginCheck also disables CSRF for backward compatibility; added deprecation warning and docs explaining the scope.
    • Added tests covering flag combinations and expected behaviors.

Written for commit 2b637daf90. 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/7204 **Author:** [@Paola3stefania](https://github.com/Paola3stefania) **Created:** 1/8/2026 **Status:** ✅ Merged **Merged:** 1/11/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/separate-csrf-and-origin-checks` --- ### 📝 Commits (10+) - [`cb48766`](https://github.com/better-auth/better-auth/commit/cb487661bd7b2ac10fbf8ab9b89e4e8d972b5f48) feat: separate disableCSRFCheck and disableOriginCheck - [`c0f2178`](https://github.com/better-auth/better-auth/commit/c0f2178c2e98bd3299502eb81e32c09e3ea37773) feat: add backward compat - [`51863b2`](https://github.com/better-auth/better-auth/commit/51863b239340399d1901e423f3e38ef503869bdf) Merge branch 'canary' into fix/separate-csrf-and-origin-checks - [`13cb150`](https://github.com/better-auth/better-auth/commit/13cb15071235cc01d082b2aa25b2e93e7d1bc6ce) refactor - [`409f413`](https://github.com/better-auth/better-auth/commit/409f413fa6f22c1ecced602ac4e9a7d8a1106b9a) fix test - [`444fd65`](https://github.com/better-auth/better-auth/commit/444fd65b44f78d8741cb09b0652f050d9aa9ce1b) docs: add default - [`9fff796`](https://github.com/better-auth/better-auth/commit/9fff79655a2bb399a6fb2b8a526b0fa2e2e3013c) fix: lint - [`641846a`](https://github.com/better-auth/better-auth/commit/641846a0de3def92f04d68e829d4db00f14e6ba3) fix: deprecate - [`fb84114`](https://github.com/better-auth/better-auth/commit/fb8411417e0a77e1c1f4adda20b76b80fe8a4f49) Merge branch 'canary' into fix/separate-csrf-and-origin-checks - [`888c124`](https://github.com/better-auth/better-auth/commit/888c1240c58bc93f03fd534870b84ee371374e27) fix: test ### 📊 Changes **10 files changed** (+365 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/reference/options.mdx` (+2 -2) 📝 `docs/content/docs/reference/security.mdx` (+33 -3) 📝 `packages/better-auth/src/api/middlewares/origin-check.test.ts` (+224 -0) 📝 `packages/better-auth/src/api/middlewares/origin-check.ts` (+50 -3) 📝 `packages/better-auth/src/api/routes/sign-in.test.ts` (+11 -1) 📝 `packages/better-auth/src/api/routes/sign-up.test.ts` (+6 -0) 📝 `packages/better-auth/src/cookies/cookies.test.ts` (+14 -4) 📝 `packages/better-auth/src/plugins/magic-link/magic-link.test.ts` (+3 -0) 📝 `packages/better-auth/src/social.test.ts` (+3 -0) 📝 `packages/core/src/types/init-options.ts` (+19 -4) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Separated CSRF protection from origin URL validation to give precise control over security and prevent misconfiguration. Flags now target one area each, with backward compatibility for existing disableOriginCheck setups. - **Bug Fixes** - CSRF check now controls origin header validation and Fetch Metadata protections. - Origin check only validates redirect-related URLs (callbackURL, redirectTo, etc.). - Middleware honors skipCSRFCheck and skipOriginCheck independently. - disableOriginCheck also disables CSRF for backward compatibility; added deprecation warning and docs explaining the scope. - Added tests covering flag combinations and expected behaviors. <sup>Written for commit 2b637daf90ae5a553c77481128dee84c6899f6fc. 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 10:00:30 -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#15390