Summary
Better Auth SSO contains domain-ownership flaws that can let an authenticated organization administrator claim an unverified email domain or exploit a verification race. Depending on configuration, matching users may be added to an attacker-controlled organization or an attacker-controlled identity provider may be linked to an existing account.
Affected context
The issue occurs in deployments using the Better Auth SSO plugin, with the organization plugin also required for the automatic-assignment path. Risk depends on domain-verification settings, provider update behavior, implicit account linking, and whether an authenticated organization owner or administrator can register or modify SSO providers.
Exploit preconditions
- Attack surface: SSO provider registration, domain verification, provider update, and automatic organization assignment
- Required access: Authenticated organization owner or administrator access for the domain-claiming path; the account-linking path depends on the exposed provider-management and verification workflows
- Trigger point: Registration or update of an SSO provider, DNS-domain verification, or implicit linking of an identity to an existing account
- Configuration requirements: The SSO plugin must be enabled; the organization plugin and automatic assignment must be enabled for the organization-membership path
- Why exploitation is possible: Domain ownership is not consistently bound to the provider and verified domain throughout the workflow, while concurrent updates may cause proof for one domain to be applied to another
Why this happens
The vulnerability reflects improper authentication and authorization of domain ownership, mapping to CWE-287: Improper Authentication. One insecure pattern accepts a provider's asserted domain when verification is disabled, allowing an authenticated administrator to associate an arbitrary domain with an organization. A separate race condition permits domain-verification state to become associated with a different provider domain during concurrent operations. Implicit account linking can then treat an attacker-controlled identity provider as trusted without sufficiently binding the verified domain, provider, and target account.
Potential impact
- Users with matching email domains could be added to an attacker-controlled organization
- Affected users could receive unintended default organization permissions
- An attacker-controlled identity provider could be linked to an existing user account
- Accounts or organization resources could be accessed without the intended domain-owner authorization
- Organizational data could be exposed, modified, or deleted
General mitigation guidance
Mitigation generally focuses on making domain ownership an explicit, consistently enforced trust boundary.
Common defensive patterns include:
- Require successful, domain-specific verification before accepting a provider or assigning users automatically
- Bind verification records cryptographically or transactionally to the exact provider, domain, and organization being updated
- Make verification and provider updates atomic, or reject stale and conflicting state transitions
- Avoid implicit account linking unless strong identity and domain correspondence checks succeed
- Apply least privilege to organization administrators and use explicit approval for provider registration
- Prefer secure-by-default settings that keep automatic assignment and implicit linking disabled
- Record and alert on provider changes, verification attempts, membership assignments, and account-linking events
How teams detect issues like this
Detection can combine static analysis, workflow review, and runtime policy enforcement.
- Search for provider-management code that trusts user-supplied domains when verification is disabled
- Review whether verification state is checked against the exact domain, provider, organization, and current update version
- Identify non-atomic verify-then-update workflows and mutable shared verification state
- Flag implicit account-linking logic that lacks strong identity, issuer, and verified-domain checks
- Use integration tests with concurrent verification and provider-update requests
- Enforce policies requiring verified domains for automatic organization assignment and requiring approval for identity-provider changes
- Monitor for unexpected domain claims, rapid provider changes, cross-organization membership assignments, and new identity links
- Neutral automated security review tools may help identify missing authorization checks and race-prone state transitions

