[PR #6509] [CLOSED] fix(core): unify account linking trust checks across SSO and core OAuth #32317

Closed
opened 2026-04-17 23:09:42 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6509
Author: @Paola3stefania
Created: 12/4/2025
Status: Closed

Base: canaryHead: feat/sso-account-linking-policy


📝 Commits (10+)

  • c7e2cfd feat: account linking
  • 001c347 docs: update
  • e659722 Merge branch 'canary' into feat/sso-account-linking-policy
  • 90b68dc feat: backwards compatibility
  • 0fa32d6 fix: add some docu for users
  • 7ca7200 feat: add more tests
  • 8a5e001 make lint happy
  • 2393bbb fix: remove extra test
  • eb65c56 Merge branch 'canary' into feat/sso-account-linking-policy
  • ee0ed18 fix: existingUserMode -> linkingPolicy

📊 Changes

9 files changed (+1537 additions, -38 deletions)

View changed files

📝 docs/content/docs/concepts/users-accounts.mdx (+33 -2)
📝 docs/content/docs/plugins/sso.mdx (+49 -1)
📝 packages/better-auth/src/oauth2/link-account.test.ts (+354 -0)
📝 packages/better-auth/src/oauth2/link-account.ts (+57 -10)
📝 packages/core/src/types/init-options.ts (+33 -0)
packages/sso/src/account-linking.test.ts (+620 -0)
📝 packages/sso/src/routes/sso.ts (+84 -24)
📝 packages/sso/src/saml.test.ts (+241 -0)
📝 packages/sso/src/utils.ts (+66 -1)

📄 Description


Summary by cubic

Unifies account linking trust checks across core OAuth and SSO. Adds an explicit auto-linking policy; core defaults to verified_email_trusted for backward compatibility, while SSO only auto-links when the provider is trusted or the domain is verified.

  • New Features

    • Introduced account.accountLinking.linkingPolicy: never, trusted_providers_only, verified_email_trusted (core default).
    • Added canAutoLinkExistingUser for SSO (OIDC/SAML) using trustedProviders or verified domain match; SSO treats verified_email_trusted as requiring a trust signal.
    • Added skipTrustCheck to handleOAuthUserInfo so SSO can bypass core trust checks after its own validation.
  • Bug Fixes

    • Consistent redirects with error=account_not_linked when auto-linking is denied.
    • Unified trust logic for OIDC and SAML to prevent unintended linking from untrusted providers.
    • Enforce bans during OAuth sign-in and clear expired bans automatically.

Written for commit 1e2f73f60a. Summary will update automatically on new commits.

Backward compatible

Existing applications that never configured accountLinking will continue to behave exactly as before. Only applications that opt in to stricter modes will get the hardened behavior.


🔄 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/6509 **Author:** [@Paola3stefania](https://github.com/Paola3stefania) **Created:** 12/4/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/sso-account-linking-policy` --- ### 📝 Commits (10+) - [`c7e2cfd`](https://github.com/better-auth/better-auth/commit/c7e2cfda1c18943233f01dd34425cab13da4c882) feat: account linking - [`001c347`](https://github.com/better-auth/better-auth/commit/001c347286560a7c33ab58f853849739fe522e67) docs: update - [`e659722`](https://github.com/better-auth/better-auth/commit/e659722202c6ee045bc5b7763d843a86a93a9bb1) Merge branch 'canary' into feat/sso-account-linking-policy - [`90b68dc`](https://github.com/better-auth/better-auth/commit/90b68dcc093a57397a8c9dbbd9b6b1d50765d0f6) feat: backwards compatibility - [`0fa32d6`](https://github.com/better-auth/better-auth/commit/0fa32d639c994632f1b2fa102aa840934ace7186) fix: add some docu for users - [`7ca7200`](https://github.com/better-auth/better-auth/commit/7ca720084bc3c002c0b55929cf4981183a3bd620) feat: add more tests - [`8a5e001`](https://github.com/better-auth/better-auth/commit/8a5e001b5fa832c0a3a8fb4015e8a824e07c380b) make lint happy - [`2393bbb`](https://github.com/better-auth/better-auth/commit/2393bbb6079e187086640af7aaf04b71d15fd1b7) fix: remove extra test - [`eb65c56`](https://github.com/better-auth/better-auth/commit/eb65c563ab3d0b8044fb7a956adda2f120a64e73) Merge branch 'canary' into feat/sso-account-linking-policy - [`ee0ed18`](https://github.com/better-auth/better-auth/commit/ee0ed1871bc537c61ce6d90df6660d24db4759b9) fix: existingUserMode -> linkingPolicy ### 📊 Changes **9 files changed** (+1537 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/concepts/users-accounts.mdx` (+33 -2) 📝 `docs/content/docs/plugins/sso.mdx` (+49 -1) 📝 `packages/better-auth/src/oauth2/link-account.test.ts` (+354 -0) 📝 `packages/better-auth/src/oauth2/link-account.ts` (+57 -10) 📝 `packages/core/src/types/init-options.ts` (+33 -0) ➕ `packages/sso/src/account-linking.test.ts` (+620 -0) 📝 `packages/sso/src/routes/sso.ts` (+84 -24) 📝 `packages/sso/src/saml.test.ts` (+241 -0) 📝 `packages/sso/src/utils.ts` (+66 -1) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Unifies account linking trust checks across core OAuth and SSO. Adds an explicit auto-linking policy; core defaults to verified_email_trusted for backward compatibility, while SSO only auto-links when the provider is trusted or the domain is verified. - **New Features** - Introduced account.accountLinking.linkingPolicy: never, trusted_providers_only, verified_email_trusted (core default). - Added canAutoLinkExistingUser for SSO (OIDC/SAML) using trustedProviders or verified domain match; SSO treats verified_email_trusted as requiring a trust signal. - Added skipTrustCheck to handleOAuthUserInfo so SSO can bypass core trust checks after its own validation. - **Bug Fixes** - Consistent redirects with error=account_not_linked when auto-linking is denied. - Unified trust logic for OIDC and SAML to prevent unintended linking from untrusted providers. - Enforce bans during OAuth sign-in and clear expired bans automatically. <sup>Written for commit 1e2f73f60a4dc922cdf33b7133ba5a1f1891c9ba. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> **Backward compatible** Existing applications that never configured accountLinking will continue to behave exactly as before. Only applications that opt in to stricter modes will get the hardened behavior. --- <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-17 23:09:42 -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#32317