Repository navigation
fix: invite the existing account for aliased emails, keep Yahoo hyphens canonical - #14172
Conversation
When a project denies aliased emails, sign-up and OAuth store the unaliased address (Gmail dots and +tags removed). Inviting the aliased form missed that account: with an OAuth identity holding the aliased address the invite failed with 409 user_email_already_exists, otherwise with 400 user_email_not_canonical. When the exact lookup misses and the policy is on, look up the unaliased form built the same way OAuth builds it (canonical local part, typed domain). Yahoo is skipped because its hyphen rule can point at another person's mailbox. The identity conflict now explains what to do instead of claiming a user with the same email exists.
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
This PR extends the membership invite flow in
Reviewed commit: 0f3b258 |
🔵 Tier A · Mergeable after minor fixes
Adds a policy-gated fallback lookup so team invitations to aliased emails resolve to existing accounts, preserving the typed domain and sending invitations to the stored address. Unmatched aliases retain canonical-email validation, and identity-conflict errors provide clearer guidance. Yahoo canonicalization now preserves hyphens, with updated library tests, so Yahoo addresses no longer need a special exclusion in the invitation lookup. Latest changes: The newest commit preserves Yahoo hyphens in shared canonicalization, removes the obsolete hyphen-removal helper and invitation-specific Yahoo exclusion, and updates the Yahoo test expectations.
Fix with agent prompt### Issue 1
src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php:157-168
**Add E2E coverage for alias-based invitation resolution**
The existing Teams E2E suites exercise membership creation and invitation delivery, but no test covers this new lookup; the isolated derivation check cannot catch selecting the wrong account or regressing the validation path. Please add API regression coverage for resolving an alias to the existing user and delivering to its stored address, plus the policy-off, unmatched-alias, and Yahoo exclusions, as required by AGENTS.md's HTTP success/failure coverage rule.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 5
⏳ Still open from earlier reviews · 1
Merged |
| if ($invitee->isEmpty() && $canonicalEmails) { | ||
| $unaliased = $email; | ||
| try { | ||
| $parsedEmail = new Email($email); | ||
| if (! (new Yahoo())->supports($parsedEmail->getDomain())) { | ||
| $unaliased = \explode('@', $parsedEmail->getCanonical(), 2)[0] . '@' . $parsedEmail->getDomain(); | ||
| } | ||
| } catch (\Throwable) { | ||
| } | ||
| if ($unaliased !== $email) { | ||
| $invitee = $dbForProject->findOne('users', [Query::equal('email', [$unaliased])]); | ||
| } |
There was a problem hiding this comment.
Add E2E coverage for alias-based invitation resolution
The existing Teams E2E suites exercise membership creation and invitation delivery, but no test covers this new lookup; the isolated derivation check cannot catch selecting the wrong account or regressing the validation path. Please add API regression coverage for resolving an alias to the existing user and delivering to its stored address, plus the policy-off, unmatched-alias, and Yahoo exclusions, as required by AGENTS.md's HTTP success/failure coverage rule.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php
Line: 157-168
Comment:
**Add E2E coverage for alias-based invitation resolution**
The existing Teams E2E suites exercise membership creation and invitation delivery, but no test covers this new lookup; the isolated derivation check cannot catch selecting the wrong account or regressing the validation path. Please add API regression coverage for resolving an alias to the existing user and delivering to its stored address, plus the policy-off, unmatched-alias, and Yahoo exclusions, as required by AGENTS.md's HTTP success/failure coverage rule.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · testing · Reply if this doesn't apply.
There was a problem hiding this comment.
Adds email canonicalization to the team-membership invite lookup so invites sent to alias forms (plus-addressing or domain aliases) resolve to the canonical account.
Key findings
- 🟡 Canonical fallback misses accounts stored under canonical domain — Create.php:157
| if ($invitee->isEmpty() && $canonicalEmails) { | ||
| $unaliased = $email; | ||
| try { | ||
| $parsedEmail = new Email($email); | ||
| if (! (new Yahoo())->supports($parsedEmail->getDomain())) { | ||
| $unaliased = \explode('@', $parsedEmail->getCanonical(), 2)[0] . '@' . $parsedEmail->getDomain(); | ||
| } | ||
| } catch (\Throwable) { | ||
| } | ||
| if ($unaliased !== $email) { | ||
| $invitee = $dbForProject->findOne('users', [Query::equal('email', [$unaliased])]); | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Canonical fallback misses accounts stored under canonical domain
The new alias fallback never matches accounts whose stored email uses the provider's canonical domain (src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php:162). The rebuild keeps the typed domain (matching the OAuth convention), but native sign-up stores and enforces the full canonical address including domain (app/controllers/api/account.php:394), so inviting [email protected] does not find an existing [email protected] account.
Additionally, Yahoo is skipped entirely (line 161) rather than only its unsafe hyphen rule, so [email protected] or [email protected] cannot find [email protected] either. In all these cases the flow falls through to the creation path, emailIsCanonical is false, and the invite fails with USER_EMAIL_NOT_CANONICAL even though the recipient's account exists. The failure is safe but defeats the fallback's purpose for a large class of legitimate alias addresses.
📋 Prompt for AI Agents
In src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php lines 157-169, extend the fallback: after computing $unaliased (canonical local part + typed domain), also compute the full canonical address via $parsedEmail->getCanonical() and, when it differs from $unaliased, run an additional $dbForProject->findOne('users', [Query::equal('email', [$canonical])]) so variant-domain invites (hotmail.com, me.com, fastmail.fm, proton.me) match native accounts holding the canonical-domain address. Also reconsider the blanket Yahoo skip at line 161: keep the hyphen rule disabled but still map variant Yahoo domains (yahoo.co.uk, ymail.com, rocketmail.com) to yahoo.com for the lookup.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
OAuth already stores and matches Yahoo hyphen aliases by the same canonical rule, so invites follow it too instead of naming a provider. If that rule is wrong it belongs in packages/emails, where it would cover OAuth, sign-up and invites together.
Security rulesNo new WARNING or ERROR findings from security rules. 32 existing findings tracked in
|
A hyphen in a Yahoo local part only appears in a disposable address, [email protected]. The nickname is chosen separately from the Yahoo ID and mail to the bare nickname is not delivered, so stripping "-keyword" produced someone else's address, or nobody's, rather than the owner's mailbox. Yahoo canonicalization now only lowercases and folds the domain. removeHyphenSubaddress had no other caller and is removed.
Only the invitee knows which email their account uses, so ask them instead of telling the inviter to use it.
Restores the packages/emails Yahoo canonicalization to main's behaviour and skips Yahoo-family domains in the invite alias lookup again, so this change only touches the invite flow.
Restores the packages/emails Yahoo change, so the invite alias lookup needs no provider-specific skip.
What does this PR do?
When a project denies aliased emails (
canonicalEmails, on for the Cloud console), sign-up and OAuth store the unaliased address:[email protected]from Google is saved as[email protected], while the identity keeps the dottedproviderEmail. Inviting the dotted form then missed the account:409 user_email_already_exists("A user with the same email already exists"), which is what an org owner hit on Cloud400 user_email_not_canonicalPOST /v1/teams/:teamId/membershipsnow does a secondusers.emaillookup when the exact one misses and the policy is on, using the unaliased form built the same way OAuth builds it (canonical local part, typed domain kept). A match invites that account, and the mail goes to its stored address, which is the same inbox.400 user_email_not_canonical.packages/emails: Yahoo keeps the hyphenThe Yahoo provider stripped everything after the last hyphen (
[email protected]→[email protected]), copied from validator.js. On Yahoo a hyphen only appears in a disposable address,[email protected]: the nickname is chosen separately from the Yahoo ID (Yahoo help) and mail to the bare nickname is not delivered. The stripped form was someone else's address or nobody's, not the owner's mailbox. Yahoo canonicalization now only lowercases and folds the domain, so the invite lookup needs no provider-specific skip.Trade-off: under deny-aliased-email, Yahoo disposable addresses are no longer rejected, so one Yahoo user can hold a few accounts (3 disposable addresses on a free account, up to 500 on Mail Plus, each created in Yahoo settings first).
Cloud's
createInvite(org create / plan / payment validation invites) needs the same lookup; that follows in a Cloud PR with theserver-cebump.Test Plan
composer lintand PHPStan on the changed file pass.bin/monorepo check emailsandbin/monorepo test emailspass (118 tests); the existing Yahoo cases now expect the hyphen to be kept.main), same project, deny-aliased-email toggled per case:main[email protected]exists, invite[email protected]user_email_not_canonical[email protected]user_email_not_canonical[email protected]with a sign-in identity holding[email protected](the incident), invite the dotted formuser_email_already_exists[email protected]user_email_not_canonicaluser_email_not_canonical[email protected]exists, invite[email protected][email protected]user_email_not_canonicalNo PHP warnings or errors in either server's logs.
Related PRs and Issues
createInvite+server-cebumpChecklist