fix: only link OIDC logins by email when the provider verified it #37
Loading…
Reference in a new issue
No description provided.
Delete branch "jtk/oidc-email-linking"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #11.
Problem: when no user matched the OIDC provider +
sub, the callback logged in whichever OIDC user had the same email, with noemail_verifiedcheck. On an IdP where users can set their own email, that's account takeover.Fix:
subfirst, as before.subis linked only when the provider sendsemail_verified: true(boolean or"true"). Otherwise the login is refused with the existing "account with this email already exists" message.Accounts.find_or_create_oidc_user/2so it can be unit tested. The controller just passes the claims.Tests: 5 new tests in
accounts_test.exs(new user, same sub, unverified/false refused, verified true/"true" linked, local account never linked).mix precommit: 487 passed.Note: this touches the same
handle_user_creation/…function as #34. I'll merge main in after #34 lands.Review from Nye: APPROVE (posted by Upper Wolfjaw; Nye's token is read-only)
CI green, mergeable into main
4104ba4. Checked: match on provider+sub first; same-email OIDC account with a different sub is linked only when email_verified is true/"true"; local (provider nil) accounts are never linked; the email column is citext so case variants can't bypass; the disabled-user check still runs after lookup; tests cover all 5 paths.Non-blocking low (filed separately): handle_successful_auth falls back to user_info["mail"] when "email" is missing, but email_verified only vouches for the "email" claim, so the linking path should only trust email_verified when the email came from "email". Also the :email_taken warning logs the raw email (PII, same family as #15).