feat: add DangerousSSOAutoLinking config flag for automatic SSO ident…#2351
feat: add DangerousSSOAutoLinking config flag for automatic SSO ident…#2351yuvalkarmi wants to merge 1 commit intosupabase:masterfrom
Conversation
| // When dangerous SSO auto-linking is enabled, treat SSO providers | ||
| // like OAuth providers - they join the default linking domain and | ||
| // will be linked to existing accounts based on email matching. | ||
| return "default" |
There was a problem hiding this comment.
🟠 Severity: HIGH
Authentication Bypass via Malicious SSO IdP: When DangerousSSOAutoLinking is enabled, SSO providers automatically trust the IdP's email verification (hardcoded EmailVerified = true in samlacs.go). A compromised or malicious SAML IdP can claim ANY email address and automatically link to/takeover existing accounts. Unlike globally trusted OAuth providers, SSO IdPs are customer-configured and may lack proper email verification controls.
Helpful? Add 👍 / 👎
💡 Fix Suggestion
Suggestion: This is a complex architectural security issue that requires multiple complementary mitigations:
-
Implement an SSO Provider Allowlist: Add configuration to explicitly specify which SSO providers are trusted for auto-linking (e.g., GOTRUE_SECURITY_SSO_AUTO_LINKING_ALLOWED_PROVIDERS). Modify GetAccountLinkingDomain() to only return 'default' for SSO providers that are on this allowlist.
-
Add Account Linking Confirmation Flow: Before completing the account link, send a confirmation email to the existing account's verified email address with a time-limited token. Only complete the link after user confirmation. This requires changes to the DetermineAccountLinking flow and new database tables for pending links.
-
Implement Enhanced Logging and Alerting: Add comprehensive audit logging for all SSO auto-linking events, including the IdP identifier, email being linked, and user IDs involved. Configure alerts for suspicious patterns (e.g., multiple linking attempts, links to privileged accounts).
-
Multi-Factor Attribute Matching: Beyond email matching, require additional IdP-provided attributes to match (e.g., name, employee ID) before allowing auto-linking. Add configuration for required matching attributes.
-
IdP Certificate Validation: Ensure SAML signature validation is enforced and add monitoring for certificate changes on SSO providers to detect potential compromises.
These changes span multiple files (linking.go, configuration.go, samlacs.go, audit logging system, and database migrations) and require careful consideration of backward compatibility and migration paths for existing deployments.
What kind of change does this PR introduce?
Feature: Add optional
GOTRUE_SECURITY_DANGEROUS_SSO_AUTO_LINKINGconfig flag to enable automatic identity linking for SSO providers.What is the current behavior?
SSO identities are always isolated - they always create new user accounts even when the email matches an existing verified user. This was intentionally implemented in PR #1098 for security reasons.
Related discussion: https://github.com/orgs/supabase/discussions/42144
What is the new behavior?
When
GOTRUE_SECURITY_DANGEROUS_SSO_AUTO_LINKING=trueis set:When disabled (default): No behavior change - SSO remains isolated.
Additional context
Why "dangerous" in the name?
Use case: Organizations with existing users (email/password or OAuth) want to enable SAML SSO without creating duplicate accounts or building custom migration flows.
Files changed:
internal/conf/configuration.go- Add config flaginternal/models/linking.go- Check flag inGetAccountLinkingDomain()internal/models/user.go- Pass flag toIsDuplicatedEmail()internal/models/linking_test.go- Add 4 new testsIsDuplicatedEmail()