Repository navigation
fix(account): keep MFA in force when an unverified address is claimed - #15144
Conversation
Signing in by email OTP, magic URL, phone OTP, password recovery or a signed-out team invite on an account whose address is unverified ran the account claim, which deleted the authenticators and turned MFA off before issuing the session. Changing the email resets its verification while MFA stays on, so control of the new inbox alone gave a fully authorised session. When the account needs two factors the claim is skipped and the address is left unverified, so the new session stays short of factors until the TOTP or other factor is presented.
|
Review complete. 🟠 2 high 💬 Inline comments (1)
📍 Findings outside the diff (1) — 🟠 1 high — defects on lines GitHub can't attach comments to🟠 High — OAuth and id-token claim paths miss the MFA guard · account.php:2028–2048 · // app/controllers/api/account.php
2028 if (!$user->getAttribute('emailVerification', false)) {
2029 $authorization->skip(fn () => User::revokeCredentials($dbForProject, $user, $project));
2030 $dbForProject->purgeCachedDocument('users', $user->getId());
2031
2032 try {
2033 $mqtt->revoke($project->getId(), $user->getId());
2034 } catch (\Throwable $error) {
2035 Console::error('Failed to revoke MQTT connections: ' . $error->getMessage());
2036 }
2037
2038 // Sent before the request's own event, which would otherwise reach the registrant with the claimant's data
2039 (clone $queueForRealtime)The PR's invariant — a proven address must not discard a second factor while MFA is in force — is applied to the magic-url, phone-token, recovery, and team-invite paths, but the two provider-claim paths still call 🧹 Nitpicks (1) — 🟢 1 low
This PR makes email verification and account claiming safe when MFA is already in force: when a user's
Reviewed commit: a0d014f |
🟢 Tier S · Ready to merge
The account sign-in and recovery flows, along with signed-out team invitation acceptance, preserve MFA and leave an address unverified when claiming it would bypass a required second factor. E2E tests cover the retained MFA state and factor across magic-link sign-in, recovery, and invitation acceptance. The latest changes add explicit Latest changes: Added
📂 Walkthrough · 4
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
There was a problem hiding this comment.
Adds an MFA guard to the account-claim and password-recovery flows so a verified address alone cannot discard a second factor, with a new e2e test covering the magic-url and recovery paths.
Key findings
- 🟠 OAuth and id-token claim paths miss the MFA guard — account.php:2028
- 🟠 MFA guard lets email squatters keep live sessions on recovery — account.php:4727
| $authorization->skip(fn () => User::revokeCredentials($dbForProject, $profile, $project)); | ||
| $claimed = true; |
There was a problem hiding this comment.
🟠 security · high
MFA guard lets email squatters keep live sessions on recovery
When MFA is in force, password recovery skips User::revokeCredentials yet still replaces the password (app/controllers/api/account.php:4727). A squatter who registered an unverified email can enroll TOTP with their own session before the real owner recovers; after recovery the password changes but the squatter's session and second factor survive, so they keep full access and the mailbox owner cannot even claim. The same guard exists in the duplicate recovery handler at app/controllers/api/account.php:5173 and in the session-claim path at app/controllers/api/account.php:257.
📋 Prompt for AI Agents
In app/controllers/api/account.php around lines 4724-4729 and the duplicate block around 5171-5175, the new $guarded = $locked->getMinimumFactors() > 1 check is used to skip User::revokeCredentials($dbForProject, $profile, $project) during password recovery. Change the logic so revokeCredentials still runs when the email is unverified (the password change must evict the registrant's sessions, tokens and MFA factors), and keep only the emailVerification => true update behind !$guarded. Apply the same split in the session-claim path at lines 257-263. Explain in a comment that the proven address justifies revoking the registrant's credentials, while only the verification flag stays unclaimed when a second factor is in force.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
What
Proving an unverified email or phone (email OTP, magic URL, phone OTP, password recovery, signed-out team invite) claims the account via
User::revokeCredentials(), which also deletes authenticators and setsmfa => false. Changing an account's email resets verification but keeps MFA on, so the new inbox alone yielded a fully authorised session.Fix
When the account needs two factors (
getMinimumFactors() > 1), skip the claim and leave the address unverified:The session is still issued but stays short of factors (
user_more_factors_required) until the second factor is presented. Recovery still resets the password, which then also needs the second factor.Applied to
createSession(email/magic URL/phone tokens),PUT /v1/account/recovery,PUT /v1/account/recovery/otp, and signed-out membership acceptance.Test
testClaimingUnverifiedEmailKeepsMFAInForce: TOTP + MFA on an unverified-email account, then magic URL and recovery each leave the session atuser_more_factors_required, withmfa, the TOTP factor andemailVerification: falseintact.Related: appwrite-labs/cloud#6666