Repository navigation
fix(account): revoke prior credentials when OAuth links an unverified account - #14801
Conversation
…aims an unverified account An account registered with an email it never verified could keep its password, sessions, tokens and MFA factors after the verified owner of that email signed in through OAuth and the account was linked to them. Revoke everything except the email when linking promotes an unverified account, in both the browser OAuth2 and the ID token flows. Co-Authored-By: Claude <[email protected]>
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
This PR hardens the identity-token email-claim flow: when a user claims an email belonging to an account with
Reviewed commit: cb5872d |
🟢 Tier S · Ready to merge
When a provider-verified OAuth email matches an unverified account, both browser OAuth and ID-token sign-in revoke the account’s prior credentials before attaching the identity; verified accounts retain the existing linking behavior. The shared revocation operation persists the cleanup atomically and removes non-email targets with their subscribers, and E2E tests cover both OAuth flows. Latest changes: The new commits persist credential revocation and the target cleanup in a transaction, and route non-email target deletion through the subscriber-aware deletion helper.
📂 Walkthrough · 4
✅ Fixed since the last review · 1
Merged |
There was a problem hiding this comment.
The PR revokes sessions, tokens, OAuth identities, and MFA targets when an unverified account's email is claimed via an identity token, with e2e coverage; two review notes on revocation atomicity and test assertions.
Key findings
- 🟡 Revocation is not atomic with the verified-email claim — account.php:1959
…ed list The adopted user is filled from getArrayCopy(), so its sessions are plain arrays and the Document-only loop in invalidateAuthentication() skipped them. Delete sessions and challenges by userInternalId like the other collections. Co-Authored-By: Claude <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
…ribers Deleting sessions and tokens early while the cleared password and MFA state waited for the request's final user update could leave a half-revoked account if anything failed in between. Revoke and persist everything in one transaction, skip blocked accounts that the claim refuses anyway, and delete SMS and push targets through Targets::delete so their topic subscriptions go too. Co-Authored-By: Claude <[email protected]>
…ified # Conflicts: # src/Appwrite/Utopia/Database/Documents/User.php # tests/e2e/Services/Account/AccountCustomClientTest.php
…ified fix(account): revoke prior credentials when OAuth links an unverified account (cherry picked from commit ebda050)
… account (backport appwrite#14801) (cherry picked from commit ebda050)
Summary
When an OAuth2 sign-in (browser flow or
POST /v1/account/sessions/id-token) with a provider-verified email matches an existing account whose email was never verified, Appwrite links the identity to that account, as documented. Until now the account kept everything it had before the link: password, sessions, tokens, MFA factors, passkeys, other identities and phone. Whoever registered the address first, without proving they own it, kept access next to the verified owner.Linking now hands the account over cleanly: when the matched account is unverified, every credential other than the email is revoked before the identity is attached. Accounts whose email is already verified link exactly as before.
I picked revoking over refusing the link. The docs say an OAuth login with a matching email links to the existing user, and refusing would break that for every project that does not require verification at sign-up. The person signing in has proven ownership of the email, so they keep the account and its data (prefs, labels, memberships, documents) and can set a new password from the account. The cost is that a legitimate owner who never verified their email loses their old password and other sign-in methods on the first OAuth login and has to set them up again.
Changes
User::revokeCredentials()onsrc/Appwrite/Utopia/Database/Documents/User.php: deletes the user's sessions, challenges, tokens, authenticators (TOTP and passkeys), identities and non-email targets (throughTargets::delete(), so subscriptions go too), and clears password, hash, password history,passwordUpdate, phone, phone verification,mfaand recovery codes. All of this happens in one transaction, and the result is mirrored on$user. Blocked accounts are skipped, since the request refuses them anyway.app/controllers/api/account.phpOAuth2 redirect andAccount/Http/Account/Sessions/IdToken/Create.php) call it when the matched account is unverified. The change is a three-line block inside the existing branch.Tests
testCreateIdTokenSessionRevokesUnverifiedAccountCredentials: an unverified email/password account linked through an ID token loses its old session and password and comes out verified. A verified account linked the same way keeps both.testOAuthVerifiedEmailRevokesUnverifiedAccountCredentials: the same check through the browser OAuth2 mock flow, in a fresh project.E2E tests are verified by CI. Pint, PHPStan and Rector pass locally.
Related: appwrite-labs/cloud#6666