Skip to content

fix(account): revoke prior credentials when OAuth links an unverified account - #14801

Merged
ChiragAgg5k merged 4 commits into
mainfrom
fix/oauth-adopt-unverified
Oct 22, 2026
Merged

ChiragAgg5k merged 4 commits into
mainfrom
fix/oauth-adopt-unverified

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

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() on src/Appwrite/Utopia/Database/Documents/User.php: deletes the user's sessions, challenges, tokens, authenticators (TOTP and passkeys), identities and non-email targets (through Targets::delete(), so subscriptions go too), and clears password, hash, password history, passwordUpdate, phone, phone verification, mfa and 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.
  • Both linking branches (app/controllers/api/account.php OAuth2 redirect and Account/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

…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]>
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Revocation is not atomic with the verified-email claim — account.php:1959
🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Verified-keep test never asserts non-password survival (AccountCustomClientTest.php:7887) — The verified-account branch of testCreateIdTokenSessionRevokesUnverifiedAccountCredentials only asserts the old session still works and password login still succeeds (tests/e2e/Services/Account/AccountCustomClientTest.php:7887-7918).

This PR hardens the identity-token email-claim flow: when a user claims an email belonging to an account with emailVerification false, the existing account is stripped of its password and hash, its sessions, tokens, OAuth identity documents, and MFA targets are revoked, and its email is cleared — preventing an attacker from inheriting a stale account's credentials. A new e2e test in the Account custom-client suite covers the revocation contract, including the verified-account case where nothing is revoked.

Files Change
app/controllers/api/account.php Adds the revocation routine invoked when an unverified account's email is claimed.
src/Appwrite/Utopia/Database/Documents/User.php Adds user-document helpers supporting the claim/revocation flow.
src/Appwrite/Platform/Modules/Account/Http/Account/Sessions/IdToken/Create.php Wires the identity-token endpoint into the new claim semantics.
tests/e2e/Services/Account/AccountCustomClientTest.php Adds e2e tests asserting revoked and kept artifacts per verification state.

Reviewed commit: cb5872d

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 22, 2026
@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The transactional cleanup addresses the previously reported subscriber leak, and I found no remaining issues in these incremental changes.

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.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 4
File Change
app/controllers/api/account.php Revokes credentials when browser OAuth links a provider-verified email to an unverified account.
src/Appwrite/Platform/Modules/Account/Http/Account/Sessions/IdToken/Create.php Applies the same revocation behavior to ID-token sign-in.
src/Appwrite/Utopia/Database/Documents/User.php Adds the shared credential revocation operation and persists credential and target cleanup atomically.
tests/e2e/Services/Account/AccountCustomClientTest.php Covers credential revocation in browser OAuth and ID-token flows, including existing behavior for verified accounts.
✅ Fixed since the last review · 1
  • Clean up subscribers when deleting non-email targets · src/Appwrite/Utopia/Database/Documents/User.php:242

Merged main (3f829a1); no changes to this PR's code since e6e0b30 · 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 A · See the inline comments. Summary

@luxor-code-review luxor-code-review Bot 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.

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

Comment thread app/controllers/api/account.php Resolved
…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]>
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/oauth-adopt-unverified (after).

Metric Before After Change
🚀 Requests/sec 189.4 195.98 ⚪ +3.5%
⏱️ Latency P50 92.1 ms 88.54 ms ⚪ -3.9%
⏱️ Latency P95 208.64 ms 206.49 ms ⚪ -1%
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 88.54 206.49 12,426 195.98 -2.15
Account 163.27 310.65 654 11.01 +6.98
TablesDB 85.93 159.94 6,758 109.55 -11.76
Storage 82.45 192.67 3,270 54.68 -1.07
Functions 121.41 236.72 1,744 30 +0.3

Top API waits (after)

API request Max wait (ms)
storage.buckets.create 534.21
account.name.update 520.01
account.prefs.update 472.25
functions.variables.update 410.96
storage.files.create 399.52

@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.

…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]>

@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

…ified

# Conflicts:
#	src/Appwrite/Utopia/Database/Documents/User.php
#	tests/e2e/Services/Account/AccountCustomClientTest.php
@ChiragAgg5k
ChiragAgg5k merged commit ebda050 into main Oct 22, 2026
168 of 173 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/oauth-adopt-unverified branch October 22, 2026 18:52
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…ified

fix(account): revoke prior credentials when OAuth links an unverified account

(cherry picked from commit ebda050)
sarbojitrana pushed a commit to sarbojitrana/appwrite that referenced this pull request Nov 2, 2026
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.

1 participant