[PR #7460] [MERGED] fix(sso): normalize SAML emails to prevent duplicate users #15575

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7460
Author: @ajaykarthikr
Created: 1/19/2026
Status: Merged
Merged: 1/20/2026
Merged by: @himself65

Base: canaryHead: fix/saml-email-normalization


📝 Commits (7)

  • 577a0e1 fix(sso): normalize SAML emails to prevent duplicate users
  • 20469ec refactor: format SAML test file according to linter rules
  • 6492062 test: use signInWithTestUser for proper test authentication
  • 4228e10 test: intialize new test cases correctly
  • 884da30 test: update saml test case
  • 654f6be test: improve mock validation
  • 3bd09f8 test: fix usage of listener in oidc test

📊 Changes

3 files changed (+230 additions, -3 deletions)

View changed files

📝 packages/sso/src/oidc.test.ts (+55 -0)
📝 packages/sso/src/routes/sso.ts (+6 -2)
📝 packages/sso/src/saml.test.ts (+169 -1)

📄 Description

Fixes inconsistent email normalization in SAML authentication flows that causes duplicate email constraint violations during SAML authentication.

  • Add .toLowerCase() to email extraction in both SAML endpoints
  • Prevent duplicate user creation attempts when email casing differs
  • Add tests for both SAML and OIDC email normalization scenarios

Closes #7052


Summary by cubic

Normalize SAML emails to lowercase during authentication to prevent duplicate users when IdPs send mixed-case emails. Adds test coverage for SAML and OIDC email normalization. Closes #7052.

  • Bug Fixes
    • Lowercase email extraction in callbackSSOSAML and acsEndpoint.
    • Tests verify no duplicate user creation with mixed-case emails in SAML and OIDC flows.

Written for commit 3bd09f8b16. 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/7460 **Author:** [@ajaykarthikr](https://github.com/ajaykarthikr) **Created:** 1/19/2026 **Status:** ✅ Merged **Merged:** 1/20/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/saml-email-normalization` --- ### 📝 Commits (7) - [`577a0e1`](https://github.com/better-auth/better-auth/commit/577a0e17825d9969926469b0df4d689e4b25d18c) fix(sso): normalize SAML emails to prevent duplicate users - [`20469ec`](https://github.com/better-auth/better-auth/commit/20469ec4abcb541db74c9b3afb295c3988f6c6b7) refactor: format SAML test file according to linter rules - [`6492062`](https://github.com/better-auth/better-auth/commit/6492062150153f06a736534253f28880ea858dac) test: use signInWithTestUser for proper test authentication - [`4228e10`](https://github.com/better-auth/better-auth/commit/4228e104a14165c93bbf21e3b3f50b3dae8a7791) test: intialize new test cases correctly - [`884da30`](https://github.com/better-auth/better-auth/commit/884da308dfeb7a8b4a01655722772aaa56fd5614) test: update saml test case - [`654f6be`](https://github.com/better-auth/better-auth/commit/654f6be99886f8de2bf693ffb5e38cffe36c4053) test: improve mock validation - [`3bd09f8`](https://github.com/better-auth/better-auth/commit/3bd09f8b161021b11cbfadfef3819238b843bbf0) test: fix usage of listener in oidc test ### 📊 Changes **3 files changed** (+230 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/sso/src/oidc.test.ts` (+55 -0) 📝 `packages/sso/src/routes/sso.ts` (+6 -2) 📝 `packages/sso/src/saml.test.ts` (+169 -1) </details> ### 📄 Description Fixes inconsistent email normalization in SAML authentication flows that causes duplicate email constraint violations during SAML authentication. - Add .toLowerCase() to email extraction in both SAML endpoints - Prevent duplicate user creation attempts when email casing differs - Add tests for both SAML and OIDC email normalization scenarios Closes #7052 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Normalize SAML emails to lowercase during authentication to prevent duplicate users when IdPs send mixed-case emails. Adds test coverage for SAML and OIDC email normalization. Closes #7052. - **Bug Fixes** - Lowercase email extraction in callbackSSOSAML and acsEndpoint. - Tests verify no duplicate user creation with mixed-case emails in SAML and OIDC flows. <sup>Written for commit 3bd09f8b161021b11cbfadfef3819238b843bbf0. 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:06:45 -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#15575