SSO account creation trusts the IdP email without checking email_verified, although the docs say it must be verified
Summary
docs/hosting/oidc.md states that the IdP must report the user's email as verified:
The IdP must report the user's email as verified, and it must match an existing user or be allowed for JIT creation. (L60)
When empty, JIT SSO account creation is allowed for any verified email. (L133)
The code never reads the email_verified claim; the string does not appear anywhere under app/, lib/ or config/. The unverified auth.info.email alone decides two things during JIT account creation:
- Which pending invitation is redeemed. The new user joins the inviting family with the invited role, which can be
admin. - Whether
ALLOWED_OIDC_DOMAINSlets the account be created.
Where
Links are at 5e9e3b1.
SessionsController#openid_connectstoresauth.info&.emailinsession[:pending_oidc_auth]for an unlinked identity (L346).OidcAccountsController#create_userlooks upInvitation.pending.find_by(email: email)and checksAuthConfig.allowed_oidc_domain?(email)with that value (L114, L119). With an invitation it setsfamily_idandrolefrom it.#linkmakes the same decision for the UI (L20-L24).- Mobile:
SessionsController#handle_mobile_sso_onboardingcomputesallow_account_creationfrom the same email (L492).Api::V1::AuthController#sso_create_accountredeems the invitation by that email (L241). AuthConfig.allowed_oidc_domain?compares only the part after@(L73).
Not affected:
- Existing users: login resolves identities by
provider+uid. - Linking an SSO identity to an existing account: this requires that account's password.
OidcIdentity#sync_user_attributes!: it does not change the user's email.
Impact
This only matters with an IdP where someone can hold an account whose email they typed in but never confirmed. Examples are Keycloak or Authentik with open self-registration or editable profile emails and no email verification. Google and Microsoft organisational accounts report verified emails and are not affected in practice.
With such an IdP, and the default AUTH_JIT_MODE=create_and_link:
- Invitation takeover. Family A invites
[email protected], possibly asadmin. While the invitation is pending (3 days), someone registers at the IdP with the unverified email[email protected]and signs in to Sure via SSO.create_userredeems Alice's invitation, and they join family A with the invited role. Alice can no longer accept it. - Domain restriction bypass. With
ALLOWED_OIDC_DOMAINS=example.com, anyone who can set an unverified@example.comemail at the IdP gets a JIT account.
Severity depends entirely on the IdP. Operators who rely on the documented behavior have no reason to expect this.
Proposed fix
- Read
email_verifiedfrom the IdP response inopenid_connectandhandle_mobile_sso_onboarding(e.g.auth.extra.raw_info), and keep it next to the email in the pending auth and the mobile linking-code cache. - Only let a verified email redeem an invitation by address or satisfy
allowed_oidc_domain?, increate_user,linkandsso_create_account. With an unverified email:- invitations can still be accepted through the emailed invitation link, which is token-based;
- the domain check fails.
- Cover the web and mobile paths with tests for verified and unverified emails.
Open question for maintainers: some IdPs don't send email_verified at all. Should a missing claim count as unverified, which is safe but could block JIT on such setups after upgrading? Or should there be a per-provider opt-out (e.g. trust_unverified_email: true in config/auth.yml / the SSO provider settings), with the docs updated accordingly?
Happy to open a PR once there's a preference on that.
Source: we-promise/sure