Skip to content

Refuse an external registration whose e-mail already has an account - #1071

Merged
KrzysztofPajak merged 7 commits into
developfrom
fix/external-registration-email-exists
Nov 19, 2026
Merged

KrzysztofPajak merged 7 commits into
developfrom
fix/external-registration-email-exists

Conversation

@KrzysztofPajak

@KrzysztofPajak KrzysztofPajak commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Issue

When someone signs in with Google or Facebook and the store does not know that external identity yet, ExternalAuthenticationService.RegisterNewUser registers a new customer with the provider's e-mail. It never checked whether a customer with that e-mail already exists.

Result: a second account with the same e-mail is created next to the original one. The original account is not taken over, because the external identity is linked to the new account, not the old one. But two accounts share one e-mail:

  • order e-mails and password recovery for that e-mail address can reach the wrong account's owner;
  • GetCustomerByEmail returns one of them, which one depends on the database.

The registration form (RegisterValidator) and the OIDC login in core already refuse an e-mail that is taken; only this path skipped the check.

While adding the check, a second problem showed up: every caller of GetCustomerByEmail / GetCustomerByUsername repeated RegisterCustomersPerStore ? storeId : "" itself. Without per-store identity the service searched only the given store, so a caller that forgot the rule silently missed customers of other stores.

Solution

  • Before registering, AuthenticateNewUser looks up the provider's e-mail in the current store, as an e-mail and, with usernames enabled, as a username (registration stores it as both).
  • When a customer has it, nothing is registered or associated, and the result is the new status ExternalAuthStatus.EmailAlreadyExists. The check runs before the registration type, so with registration disabled the owner is still told to sign in and connect, not that registration is closed.
  • A provider that shares no e-mail (e.g. Facebook without the e-mail permission) no longer registers an account with an empty e-mail and username; the result is the new status ExternalAuthStatus.EmailRequired.
  • ExternalSignInService shows two new resources on the external authentication error page: Account.AssociatedExternalAuth.EmailAlreadyExists (sign in, recover the password if you never set one, then connect) and Account.AssociatedExternalAuth.EmailRequired. Both are in DefaultLanguage.xml and Upgrade/en_250.xml.
  • CustomerManagerService.RegisterCustomer itself refuses an e-mail, or with usernames enabled a username, that another customer already has. Every registration path still answers this itself with a proper message; the guard stops a path that forgot to (future plugins, API) and narrows the window between two concurrent registrations. It does not close that window completely - only a unique index would, and with guests (empty e-mail) and per-store identity that is a separate change.
  • CustomerService.GetCustomerByEmail and GetCustomerByUsername own the per-store rule: the store narrows the lookup only with Customer:RegisterCustomersPerStore; otherwise the lookup is global. Callers pass the store as it is, and the repeated checks are gone (account controller, storefront validators, admin customer validator and service, merchandise return search, OIDC resolver and profile sync, frontend API login).

The existing customer signs in with their password and connects Google/Facebook from their account. That path (AuthenticateNewUser with a signed-in customer) is unchanged.

Breaking changes

  • ExternalAuthStatus has two new values. Code that switches over it without a default should handle EmailAlreadyExists and EmailRequired.
  • ICustomerManagerService.RegisterCustomer throws GrandException for an e-mail or username used by another customer. Custom registration code should check first, as the built-in paths do.
  • Without per-store identity, GetCustomerByEmail / GetCustomerByUsername with a store id no longer search only that store; they search all stores, as with an empty store id. Every caller in the repository already passed an empty store id in that mode, so behaviour does not change for them; custom code that relied on the store-only search does.
  • CustomerConfig was removed from the constructors that only used it for that check: AccountController, TokenWebController, LoginWebValidator, OidcProfileSynchronizer, MerchandiseReturnViewModelService, and the storefront validators RegisterValidator, LoginValidator, PasswordRecoveryValidator, PasswordRecoveryConfirmValidator, SubAccountCreateValidator, SubAccountEditValidator, CustomerInfoValidator.

Testing

  • Grand.Business.Customers.Tests: 156 passed. With per-store identity off, a store id no longer narrows the e-mail and username lookups; RegisterCustomer refuses another customer's e-mail or username and accepts the registering customer's own.
  • Grand.Business.Authentication.Tests: 403 passed. An unknown identity with a taken e-mail or username registers nobody and stores no association, also with registration disabled; one without an e-mail is refused.
  • Grand.Web.Common.Tests 759, Grand.Web.Tests 619, Grand.Module.Api.Tests 110, Grand.Modules.Tests 398: all passed. Grand.Web.Admin.Tests 2058 and Grand.Web.Store.Tests 241 passed before the last commit, which does not touch those projects.
  • The whole solution (GrandNode.slnx) builds.
  • Not tested against a real Google/Facebook account.

A Google or Facebook sign-in with an unknown identity registered a new
customer with the provider's e-mail without checking it, so a second
account with the same e-mail could exist next to the original one. The
registration now applies the same rule as the registration form (per store
when customers register per store) and shows "The specified email already
exists"; the existing customer signs in and connects the provider instead.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 14:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

support added 6 commits November 19, 2026 17:54
GetCustomerByEmail and GetCustomerByUsername ignore the store unless customers register per store, so callers pass the store as it is instead of repeating the RegisterCustomersPerStore check.
- Refuse a provider e-mail that is another customer's username, and a provider that shares no e-mail
- Check the e-mail before the registration type, so the owner learns to sign in and connect
- Tell the customer what to do next instead of the registration form's message
- Refuse a taken e-mail or username in RegisterCustomer itself, for every registration path
- Inline the store id aliases and fix the stale OIDC lookup comment
…tration-email-exists

# Conflicts:
#	src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
…tration-email-exists

# Conflicts:
#	src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
@KrzysztofPajak
KrzysztofPajak merged commit eec1d7e into develop Nov 19, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the fix/external-registration-email-exists branch November 25, 2026 09:10
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