Skip to content

fix(sso): refuse SSO callback user writes outside the provider's verified domain - #10060

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/sso-jit-domain-gate
Nov 14, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/sso-jit-domain-gate

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Better Auth checks an SSO provider's domain only when linking an existing account; just-in-time creation (and overrideUserInfo updates) wrote whatever email the IdP asserted, and Sim's domain check in the admission after-hook ran only once the row was committed
  • databaseHooks.user.create.before / update.before now refuse an SSO callback write unless the provider's domain is verified and the email belongs to it, so the row is never written
  • The provider lookup goes through Better Auth's transaction adapter (getCurrentAdapter), and the refusal carries sso_provisioning_failed as both message and code so create and update both redirect to the SSO page
  • isEmailInSSODomain in @sim/utils/sso-domain is shared with the admission use case so both checks use the same canonical comparison

Type of Change

  • Bug fix

Testing

  • New lib/auth/sso/callback-email-domain.integration.ts: real OIDC sign-in through auth.handler against PostgreSQL with a local IdP — out-of-domain create refused (no user/account), in-domain create still succeeds, overrideUserInfo cannot rewrite a linked user's email
  • Red→green: removing the create hook, the update hook, or the error code each fails its test
  • Existing integration suites pass: admit-sso-user, lifecycle-audit, provider-concurrency, primary-provider
  • Unit: lib/auth, app/api/auth, ee/sso (733 tests), packages/utils sso-domain
  • biome, check:comment-hygiene, file-names, source-conventions, test-patterns, utils, boundaries, explicit-any, source-text

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Ignored Ignored Preview Nov 14, 2026 10:26pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The PR appears safe to merge; the latest change fixes the previous foreign-email finding.

Summary

The PR checks an SSO provider’s verified domain before creating or changing a user’s email.

  • SSO callbacks save user emails only when they match a verified provider domain.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[SSO callback] --> B[Before user write]
  B --> C{Provider verified and email domain matches?}
  C -->|No| D[Refuse write]
  C -->|Yes| E[Write user]
  E --> F[Check SSO admission]
Loading

Reviews (2) · Last reviewed commit: "fix(sso): read the mailbox domain after ..." · Reviewed by Greptile

Comment thread packages/utils/src/sso-domain.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files

Turn on auto-fix | Re-trigger cubic

Comment thread packages/utils/src/sso-domain.ts Resolved
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 2442320 into staging Nov 14, 2026
158 of 160 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/sso-jit-domain-gate branch November 14, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant