Skip to content

fix(account): verify the account a provider sign-in adopts by email - #14283

Merged
HarshMN2345 merged 8 commits into
mainfrom
fix/oauth-email-verification
Oct 9, 2026
Merged

HarshMN2345 merged 8 commits into
mainfrom
fix/oauth-email-verification

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

People who sign up with Google could land on "Verify your email" on Cloud even though Google had already vouched for the address.

A fresh Google user is already created verified from Google's email_verified claim. But when an unverified account with the same email already exists (an unfinished password sign-up, or the user an org invite creates), the OAuth2 callback and the ID-token session adopt that account on the verified-email match and leave emailVerification false.

The email-match branch in both flows now marks the account verified when its stored email is on the provider email's domain, which covers the canonical form stored for aliased addresses (e.g. [email protected] signing into [email protected]).

Test Plan

Against an API container running this branch on the local stack:

  • testOAuthVerifiedEmailCanLinkToExistingAccount (browser OAuth2) and testCreateIdTokenSessionEmailCollision (ID token) now assert the adopted account is verified. Each fails against main's code and passes here.
  • Dotted Gmail ID token adopting a dotless account with the aliased-email policy on: verified.
  • Existing OAuth2, ID-token and identity tests in AccountCustomClientTest pass (37 tests).

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

When an OAuth2 or ID-token sign-in matches an existing account by a
provider-verified email, the account was adopted but kept
emailVerification false. Accounts left unverified by an unfinished
password sign-up or an invite then hit email verification right after
signing in with Google, although Google had already vouched for the
address.

Mark the adopted account verified when its email is on the provider
email's domain, which covers the canonical form stored for aliased
addresses such as dotted Gmail.
Only the password sign-up page sent a verification email, so every
other way onto /verify-email (OAuth2, sign-in, the auth guard) said a
link had been sent when none was.

The page now sends the link itself, once per account per tab session so
a reload does not mail another, and sign-up no longer sends its own.
The resend button reads its pending state from the mutation cache: the
automatic send starts in a mount effect, and a remount detaches the
component's observer from it, leaving the button disabled.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)


This PR changes both the console email-verification flow and the OAuth/OAuth2 account-adoption paths. On the backend, two adoption branches (legacy account.php OAuth and the new IdToken resolveUser) now set emailVerification=true when the adopted user's email domain matches the provider-asserted email domain. On the frontend, sign-up no longer sends the verification email itself and simply navigates to /verify-email, which now owns the send with a claim-based dedupe (in-memory Set plus a sessionStorage key) to survive remounts and reloads, and pending state is tracked via useIsMutating so it survives observer detachment.

Files Change
app/controllers/api/account.php, src/Appwrite/Platform/Modules/Account/Http/Account/Sessions/IdToken/Create.php Mark adopted accounts email-verified when the provider email domain matches the adopted account's domain
apps/console/src/routes/_auth/sign-up.tsx Drop the sign-up-time verification send; defer to the /verify-email page
apps/console/src/routes/_auth/verify-email.tsx Auto-send the verification link on mount with a per-tab claim dedupe and remount-safe pending state

Reviewed commit: 0bcbc7c

@ghost

ghost commented Oct 9, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental changes only clarify comments, and the previously reviewed behavior remains unchanged.

OAuth2 and ID-token sign-in now mark an existing account verified when a verified provider email matches it on the same domain, including canonicalized aliases. The E2E tests cover the adopted-account behavior, and the latest commits clarify the provider-verification rationale in both flows.

Latest changes: The newest commits revise the comments in both adoption branches to say the provider verified the address or its canonical form on the same domain.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
app/controllers/api/account.php Marks an adopted OAuth2 account verified for a verified provider email on the same domain; clarifies the verification rationale.
src/Appwrite/Platform/Modules/Account/Http/Account/Sessions/IdToken/Create.php Applies the same verified-email adoption behavior to ID-token sessions and clarifies the rationale.
tests/e2e/Services/Account/AccountCustomClientTest.php Asserts that existing accounts adopted through OAuth2 and ID-token sign-in are verified.

Reviewed the commits since e602443 · 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

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • 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.

@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 moves console email-verification link sending from sign-up to the /verify-email page with per-tab dedupe, and auto-marks adopted OAuth accounts verified when the provider-asserted email shares the domain.

Key findings

Comment on lines +73 to +85
function claimVerificationSend(accountId: string): boolean {
if (sentVerifications.has(accountId)) return false
sentVerifications.add(accountId)
try {
if (sessionStorage.getItem(SENT_VERIFICATION_STORAGE_KEY) === accountId) {
return false
}
sessionStorage.setItem(SENT_VERIFICATION_STORAGE_KEY, accountId)
} catch {
// Storage can be unavailable (private mode); a reload then sends again.
}
return true
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 bug · medium

Verification send claimed before the send succeeds

The auto-send claim is committed before the request is known to have succeeded: claimVerificationSend adds the account to the module Set and writes sessionStorage before resendMutation.mutate() fires (apps/console/src/routes/_auth/verify-email.tsx:73). On failure the onError handler only shows a toast, so a failed createEmailVerification (network error, rate limit) permanently consumes the automatic send for that account in this tab; a remount or full page load never retries. The user lands on a page implying a link was sent with no persistent error indication.

📋 Prompt for AI Agents

In apps/console/src/routes/_auth/verify-email.tsx, make the automatic verification send retryable: change claimVerificationSend (lines 73-85) into a check-only skip test, and move the sentVerifications.add(accountId) and sessionStorage.setItem(SENT_VERIFICATION_STORAGE_KEY, accountId) writes into resendMutation's onSuccess (around line 246) — e.g. invoke resendMutation.mutate(undefined, { onSuccess: () => commitVerificationSend(accountId) }) from the mount effect at lines 262-266. Why: the claim is currently consumed before the request resolves, so a failed automatic send is never retried on reload or remount and the user silently receives no email.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/oauth-email-verification (after).

Metric Before After Change
🚀 Requests/sec 195.47 205.6 🟢 +5.2%
⏱️ Latency P50 87.72 ms 84.73 ms ⚪ -3.4%
⏱️ Latency P95 215.58 ms 194.39 ms 🟢 -9.8%
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 84.73 194.39 12,882 205.6 -21.19
Account 158.53 299.04 678 11.22 -19.05
TablesDB 82.54 158.65 7,006 114.12 -11.17
Storage 77.53 166.51 3,390 57.27 -20.99
Functions 119.79 221.95 1,808 31.24 -29.82

Top API waits (after)

API request Max wait (ms)
account.prefs.update 423.47
account.name.update 409.23
storage.buckets.create 346.26
tablesdb.rows.increment 338.51
functions.variables.update 336.09

composer audit fails on three advisories against 0.22.0 and earlier
(stored XSS via DTD entities, mixed-case xlink:href skipping the <use>
nesting check, DTD attribute declaration crash). 1.0.0 is not affected
and keeps the minify()/sanitize() API the favicon endpoint uses.
… impersonators

One sessionStorage value held only the last account sent a link, so
switching accounts in a tab and reloading mailed the first account
again. Each account now gets its own key.

Impersonators cannot write to the account, so the automatic send would
only fail with a read-only error toast; skip it while impersonating,
like the other automatic account writes.
Both adoption tests, browser OAuth2 and ID token, now check that the
adopted account comes back verified. Each assertion fails without the
fix.

@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

The console half of this fix ships separately; this branch keeps the server change and its tests.
@HarshMN2345 HarshMN2345 changed the title Fix: provider sign-in leaves an existing account unverified, verify page never sends email Fix: provider sign-in leaves an existing same-email account unverified Oct 9, 2026
@HarshMN2345 HarshMN2345 changed the title Fix: provider sign-in leaves an existing same-email account unverified fix(account): verify the account a provider sign-in adopts by email Oct 9, 2026
@HarshMN2345
HarshMN2345 merged commit fbfb848 into main Oct 9, 2026
59 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.

1 participant