Skip to content

fix(auth): claim the account when an unverified phone is proven - #15058

Merged
ArnabChatterjee20k merged 2 commits into
mainfrom
security/account-claim-phone-parity
Oct 29, 2026
Merged

ArnabChatterjee20k merged 2 commits into
mainfrom
security/account-claim-phone-parity

Conversation

@ArnabChatterjee20k

Copy link
Copy Markdown
Member

What does this PR do?

Proving an unverified email already claims the account: User::revokeCredentials drops whatever the registrant kept (password, sessions, tokens, MFA, passkeys, identities, account keys, the phone and non-email targets). Proving an unverified phone did nothing of the kind, so an account registered with someone else's phone kept the registrant's password and sessions after the phone's owner signed in.

This mirrors the claim for phone at every site where a signed-out caller proves a phone:

  • Token exchange ($createSession: PUT /v1/account/sessions/phone, POST /v1/account/sessions/token): a phone OTP on an account whose phoneVerification is false now runs the claim, under the same user row lock and transaction as the email branch.
  • Membership status update: accepting a phone invite while signed out on a phone-only account with an unverified phone now runs the claim, as the email invite does.

revokeCredentials takes the proven channel (MESSAGE_TYPE_EMAIL by default, or MESSAGE_TYPE_SMS). It keeps the proven address and its targets, and drops the other address: an email claim drops the phone (unchanged), a phone claim drops the email and its metadata.

Semantics

The email claim fires whenever the proven email is unverified, regardless of a verified phone, and drops that phone. The phone claim is the exact mirror: it fires whenever the proven phone is unverified, regardless of a verified email, and drops that email. Leaving the email in place would keep a way back in for whoever registered the account (password recovery or email OTP to their own address), so the claim would not hold. Sites that are not claims stay as they are: verifying a phone while signed in, and accepting an invite while signed in, change nothing.

Test Plan

  • New e2e AccountCustomClientTest::testCreatePhoneSessionRevokesUnverifiedAccountCredentials: a registrant with a password and a verified email adds a phone they do not own; the phone's owner signs in by OTP. Asserts the registrant's session and password are rejected and the email is gone, while the owner's session works with phoneVerification true.
  • New e2e TeamsCustomClientTest::testUpdateMembershipStatusByPhoneRevokesUnverifiedAccountCredentials: an anonymous account adds a phone it does not own; the phone's owner accepts an invite signed out. Asserts the registrant's session is rejected.
  • Both fail without the fix (the registrant's session still returns 200) and pass with it.
  • Account phone, token and claim tests and the full Teams client suite pass.
  • Pint passes. PHPStan level 4 on the touched files reports nothing new.

Related PRs and Issues

Tracking: appwrite-labs/cloud#7065

🤖 Generated with Claude Code

ArnabChatterjee20k and others added 2 commits October 28, 2026 17:35
Proving an unverified phone by OTP sign-in or a signed-out team invite
must revoke whatever the registrant kept, as an unverified email does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A phone OTP sign-in or a signed-out phone invite now revokes the
registrant's credentials, mirroring the email claim. The claim keeps the
proven phone and drops the email, as the email claim drops the phone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR makes account-claim revocation channel-aware: User::revokeCredentials() now accepts a $proven argument, so when the new registrant proves the phone channel, the prior owner's email and all derived email fields (emailCanonical, emailIsCanonical, emailIsCorporate, emailIsDisposable, emailIsFree) are wiped in the same transaction — and symmetrically, proving email wipes phone. The token-exchange, recovery, OAuth2 IdToken, and team-membership claim call sites in account.php and Memberships/Status/Update.php pass the correct proven channel, and e2e coverage is added for both Account and Teams claim flows. Verified review of the wipe coverage, unique-index release, and transaction mirroring found no data-integrity gaps; one candidate (unconditional email wipe on the SMS branch even when the email was already verified) fell below the confidence threshold and is noted here only for awareness.

Files Change
src/Appwrite/Utopia/Database/Documents/User.php Adds $proven parameter to revokeCredentials(); SMS path wipes email plus all derived email attributes, email path wipes phone, within the existing single transaction.
app/controllers/api/account.php Token-exchange and recovery/OAuth2 IdToken call sites pass the proven channel into revokeCredentials().
src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php Team-membership claim confirmation passes the proven channel so revocation matches the verified contact.
tests/e2e/Services/Account/AccountCustomClientTest.php, tests/e2e/Services/Teams/TeamsCustomClientTest.php New e2e cases covering channel-aware credential revocation on both claim flows.

Reviewed commit: 9860d11

@ghost

ghost commented Oct 28, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

This change claims accounts when an unverified phone is proven during phone-token exchange or signed-out phone-invite acceptance. Credential revocation now preserves the proven channel and removes the other address, with end-to-end coverage for both flows.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 5
File Change
app/controllers/api/account.php Runs channel-aware credential revocation when an email or phone token proves an unverified address.
src/Appwrite/Platform/Modules/Teams/Http/Memberships/Status/Update.php Applies the matching claim when a signed-out user accepts an invite proving a single unverified address.
src/Appwrite/Utopia/Database/Documents/User.php Generalizes credential revocation to retain the proven address and its targets.
tests/e2e/Services/Account/AccountCustomClientTest.php Covers phone OTP account claiming and verifies the registrant's credentials no longer work.
tests/e2e/Services/Teams/TeamsCustomClientTest.php Covers signed-out phone-invite acceptance and verifies the registrant's session is revoked.
🔇 Filtered out · 1

Findings Hansi considered but did not post.

Finding Why
Phone invite response leaks the discarded email Verifier: The claimed discard cannot occur on this path: Update.php:181–186 selects phoneVerification only when the locked user has a phone and no email. With both addresses present, verification is null and revokeCredentials is not called. Thus this phone-invite claim only clears an already-empty email; it does not discard a previous registrant's nonempty email as alleged. The separate targetUser document alone does not establish the reported leak.

Reviewed 9860d11 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → security/account-claim-phone-parity (after).

Metric Before After Change
🚀 Requests/sec 158.89 166.44 ⚪ +4.7%
⏱️ Latency P50 108.15 ms 104.27 ms ⚪ -3.6%
⏱️ Latency P95 263.2 ms 245.82 ms 🟢 -6.6%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 104.27 245.82 10,374 166.44 -17.39
Account 202.5 390.4 546 9.04 +12.53
TablesDB 101.88 194.69 5,642 92.42 -26.95
Storage 93.43 225.62 2,730 47.05 -5.03
Functions 140.19 280.85 1,456 25.76 -15.06

Top API waits (after)

API request Max wait (ms)
account.name.update 580.56
account.prefs.update 528.03
account.get 491.56
storage.buckets.create 470.84
functions.create 458.19

@ArnabChatterjee20k
ArnabChatterjee20k merged commit b78a6fa into main Oct 29, 2026
70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants