Skip to content

fix(account): match existing users by exact email on OAuth and ID-token sign-in - #14778

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/oauth-email-identity
Oct 22, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/oauth-email-identity

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

OAuth and ID-token sign-in looked up an existing user by the provider email plus its cross-domain canonical form from utopia-php/emails (for example, Outlook folds hotmail, live and msn domains into outlook.com). Account matching now uses only the provider's own address: as given, lowercased, and, when canonical emails are enabled for the project, the delivery-safe form that keeps the provider domain. The canonical form is still stored as emailCanonical metadata and used by the aliased-email policy.

The same list backs the email backfill uniqueness check for users created without an email, so that check now also compares exact addresses.

The mock OAuth provider's canonical- client ID now returns the address after the prefix when it contains @, so e2e tests can sign in with any address.

Test plan

  • composer lint, PHPStan and composer refactor:check on the changed files
  • CI Account lane: testCreateIdTokenSessionMatchesExactEmail (same address in another case adopts the account; an address on another domain of the same mail provider gets a separate user)
  • CI Account lane: testCreateOAuth2SessionMatchesExactEmail (OAuth sign-in with an address on another domain of the same mail provider gets a separate user)

Related: appwrite-labs/cloud#6666

@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Mock OAuth endpoint now returns any verified email — mock.php:178

The change hardens identity matching in three OAuth entry points so users are linked by the provider-reported email (and its lowercase form) rather than the canonicalized local-part-plus-provider-domain address, preventing cross-domain account collisions. It also teaches the mock OAuth /user endpoint to return the email encoded in canonical-<email> tokens as a verified address, enabling e2e coverage of the new matching rule.

Files Change
app/controllers/api/account.php Removes the canonical email from the OAuth user-matching set at both session-creation sites.
src/Appwrite/Platform/Modules/Account/Http/Account/Sessions/IdToken/Create.php Applies the same provider-email-only matching for IdToken-based session exchange.
app/controllers/mock.php Mock OAuth user endpoint now returns arbitrary emails from canonical-<email> tokens as verified addresses.
tests/e2e/Services/Account/AccountCustomClientTest.php Adds e2e coverage exercising provider-email matching via the mock provider.

Reviewed commit: 588f2c7

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

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new backfill regression covers the previously open exact-email collision case, and I found no remaining issue in the incremental changes.

OAuth and ID-token sign-in now match existing accounts using the provider’s exact address and its same-domain normalized form, while retaining canonical email metadata and aliased-email policy checks. The same candidates are used for email backfill collision checks, and the mock OAuth profile can supply arbitrary addresses only in development. E2E coverage exercises case-insensitive matching, separation across Outlook-family domains, and ID-token backfill onto an email-less account.

Latest changes: The newest commits limit arbitrary mock OAuth email responses to development and add coverage for ID-token backfill when another Outlook-family domain already owns the canonical alias.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 4
File Change
app/controllers/api/account.php Limits OAuth account matching and email backfill collision checks to provider-address candidates.
app/controllers/mock.php Supports address-based mock profiles in development while retaining the fixed mock address behavior elsewhere.
src/Appwrite/Platform/Modules/Account/Http/Account/Sessions/IdToken/Create.php Applies exact provider-address matching and backfill collision checks for ID-token sign-in.
tests/e2e/Services/Account/AccountCustomClientTest.php Adds OAuth and ID-token coverage for exact-address matching, cross-domain separation, and anonymous-account email backfill.
✅ Fixed since the last review · 1
  • Cover exact-email behavior during email backfill · src/Appwrite/Platform/Modules/Account/Http/Account/Sessions/IdToken/Create.php:676

Reviewed the commits since 588f2c7 · 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 · Looks good to merge. 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.

This PR fixes OAuth canonical-email account matching by matching users only on the provider-reported email instead of the locally canonicalized address, and extends the mock OAuth provider to let tests supply arbitrary verified emails.

Key findings

  • 🟡 Mock OAuth endpoint now returns any verified email — mock.php:178

Comment thread app/controllers/mock.php Resolved
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

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

Metric Before After Change
🚀 Requests/sec 209.12 202.36 ⚪ -3.2%
⏱️ Latency P50 82.46 ms 84.76 ms ⚪ +2.8%
⏱️ Latency P95 193.62 ms 203.54 ms 🔴 +5.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 84.76 203.54 12,540 202.36 +9.93
Account 160.57 301.41 660 11.42 +39.57
TablesDB 80.91 154.84 6,820 112.59 +0.81
Storage 80.24 190.32 3,300 56.09 +9.94
Functions 118.61 231.25 1,760 30.57 +8.48

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.delete 454.17
functions.create 435.37
storage.buckets.create 422.11
account.name.update 419.08
account.prefs.update 409.9

@github-actions

github-actions Bot commented Oct 22, 2026 •

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.

@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

@ChiragAgg5k
ChiragAgg5k merged commit 6dcbef4 into main Oct 22, 2026
75 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/oauth-email-identity branch October 22, 2026 16:32
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
fix(account): match existing users by exact email on OAuth and ID-token sign-in

(cherry picked from commit 6dcbef4)
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