Make WordPress Core

Opened 7 weeks ago

Last modified 2 weeks ago

#66238 new enhancement

Users with "same" email address can be accidentally created

Reported by: flymike Owned by:
Priority: normal Milestone: Awaiting Review
Component: Login and Registration Version: 2.1
Severity: normal Keywords: has-patch has-screenshots changes-requested has-unit-tests
Cc: Focuses: administration

Description

Wordpress does not permit multiple users with the same email address, using RFC 5321 to define the localpart of the address.
However, several major email service providers (Gmail, Outlook, Yahoo) ignore mixed case in localparts.
This means that WordPress will support 2 users with email addresses abc@… and ABc@… - although those 2 addresses represent the same mailbox.
Propose an enhancement:

  1. Warn admins when manually creating a user that the new email address might be a duplicate of...
  2. Highlight email addresses on the admin Users page that are case-insensitive identical.

Attachments (4)

66238.diff​ (8.9 KB ) - added by ravipatel 6 weeks ago.
On a default install, case-variant duplicates are already rejected, because wp_users.user_email uses a _ci collation. The issue appears with case-sensitive collations (*_bin), with SQLite, and with data created under WP_IMPORTING. This patch makes email_exists() case-insensitive regardless of collation and flags existing duplicates on the Users screen. Tradeoff: the LOWER(user_email) lookups can't use the index.
66238-before-patch.png​ (17.8 KB ) - added by ravipatel 6 weeks ago.
We have register 2 diffrent users in it.
66238-1.png​ (37.3 KB ) - added by ravipatel 6 weeks ago.
We changed subsriber emaill same as Admin email with uppercase name and without error updated.
66238-2-afterpatch.png​ (56.6 KB ) - added by ravipatel 6 weeks ago.
After this patch we have set a error notification in it.

Download all attachments as: .zip

Change History (18)

@ravipatel
6 weeks ago

On a default install, case-variant duplicates are already rejected, because wp_users.user_email uses a _ci collation. The issue appears with case-sensitive collations (*_bin), with SQLite, and with data created under WP_IMPORTING. This patch makes email_exists() case-insensitive regardless of collation and flags existing duplicates on the Users screen. Tradeoff: the LOWER(user_email) lookups can't use the index.

@ravipatel
6 weeks ago

We have register 2 diffrent users in it.

@ravipatel
6 weeks ago

We changed subsriber emaill same as Admin email with uppercase name and without error updated.

@ravipatel
6 weeks ago

After this patch we have set a error notification in it.

#1 @ravipatel
6 weeks ago

  • Focuses administration added
  • Keywords has-patch has-screenshots added
  • Priority normal → high
  • Severity normal → major

#2 in reply to: ↑ description @westonruter
6 weeks ago

  • Keywords changes-requested added
  • Priority high → normal
  • Severity major → normal
  • Version 7.1.2 → 2.1

Replying to flymike:

However, several major email service providers (Gmail, Outlook, Yahoo) ignore mixed case in localparts.

I think the vast majority of email providers would ignore the casing. RFC 5321 indicates that it “may be case-sensitive”:

   Local-part     = Dot-string / Quoted-string
                  ; MAY be case-sensitive

So this seems to imply that the default state is for it to not be case sensitive, which is reflected in this being the standard behavior.

So yes, I think this is valid.

@ravipatel Please open a pull request with your patch to make it easier to review and so that the automated checks in CI can run.

Tradeoff: the LOWER(user_email) lookups can't use the index.

This is a big tradeoff and it would probably be a non-starter for large multisite installs. In this case, perhaps the LOWER check should only be done in the cases where we know a case-insensitive collation isn't being used. Otherwise, a new table column could be added to store the lower-case version, but this may be excessive if the default is to use a case-insensitive collation (and therefore this seems a normal priority).

This ticket was mentioned in ​PR #14053 on ​WordPress/wordpress-develop by ​@ravipatel.


6 weeks ago
#3

  • Keywords has-unit-tests added

Trac ticket: https://core.trac.wordpress.org/ticket/66238

What

email_exists() now matches emails case-insensitively regardless of the DB collation, so ABc@example.com can't be registered when abc@example.com exists. The Users list table flags existing case-variant duplicates so they can be cleaned up.

Index tradeoff (from Trac feedback)

The LOWER(user_email) lookup now only runs when the user_email column has a case-sensitive collation (*_bin, *_cs) or the collation can't be determined. With the default *_ci collation, the existing indexed lookup already ignores case, so no extra query is made.

The list table check only queries the email addresses on the current page, using user_email IN (...) on *_ci collations so the index is used.

Collation detection is cached per request in the private _wp_is_user_email_case_sensitive() and can be overridden with the wp_is_user_email_case_sensitive filter.

Testing

  1. npm run test:php -- --group 66238 (covers both the case-insensitive and case-sensitive paths).
  2. Create a user abc@example.com, then try to add ABc@example.com: it should be rejected with "This email address is already registered".

#4 @ravipatel
6 weeks ago

  • Keywords has-unit-tests removed

@westonruter Thanks for the review! PR: ​https://github.com/WordPress/wordpress-develop/pull/14053

Following your suggestion, the LOWER() lookup now only runs when the user_email column's collation is case-sensitive (or unknown). On the default *_ci collations the existing indexed lookup already handles it, so there's no extra query and no index tradeoff. The users list table check was also reworked to only look up the emails on the current page, using the index on *_ci collations.

If a lower-case column is still preferred for case-sensitive installs, I'm happy to explore that in a follow-up.

​@ravipatel commented on ​PR #14053:


6 weeks ago
#6

Thanks @westonruter! Just a heads-up: my fork was created from another fork (ravikumarup/wordpress-develop) rather than directly from WordPress/wordpress-develop, so "Allow edits by maintainers" may not let you push to this branch. To avoid that, I've invited you as a collaborator on rvpatel/wordpress-develop. Once you accept the invitation, you should be able to push changes directly to the trac-66238 branch. I'll re-fork from the official repository once my open PRs are wrapped up.

​@ravipatel commented on ​PR #14053:


6 weeks ago
#7

@westonruter The PR has been updated to address the review feedback: the LOWER() lookup now runs only when the user_email column uses a case-sensitive collation, so the default *_ci setup keeps using the index. It's also up to date with trunk and all checks pass. Ready for another review when you have time.

This ticket was mentioned in ​PR #14209 on ​WordPress/wordpress-develop by ​@ravipatel.


5 weeks ago
#8

  • Keywords has-unit-tests added

Replaces #14053, which was opened from a nested fork. Previous review history is there.

What

email_exists() now matches emails case-insensitively regardless of the DB collation, so ABc@example.com can't be registered when abc@example.com exists. The Users list table flags existing case-variant duplicates so they can be cleaned up.

Index tradeoff (from Trac feedback)

The LOWER(user_email) lookup now only runs when the user_email column has a case-sensitive collation (*_bin, *_cs) or the collation can't be determined. With the default *_ci collation, the existing indexed lookup already ignores case, so no extra query is made.

The list table check only queries the email addresses on the current page, using user_email IN (...) on *_ci collations so the index is used.

Collation detection is cached per request in the private _wp_is_user_email_case_sensitive() and can be overridden with the wp_is_user_email_case_sensitive filter.

Testing

  1. npm run test:php -- --group 66238 (covers both the case-insensitive and case-sensitive paths, including a successful LOWER() fallback when the exact lookup misses).
  2. Create a user abc@example.com, then try to add ABc@example.com: it should be rejected with "This email address is already registered".

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Reworking the patch to address the Trac feedback (limiting the LOWER() lookup to case-sensitive collations), the list table query, PHPUnit tests, and running PHPCS/PHPUnit/PHPStan; also the latest review fixes. I reviewed and tested the final implementation and take responsibility for it.

​@ravipatel commented on ​PR #14053:


5 weeks ago
#9

Comment on old #14053. It should already be closed automatically because you deleted the fork, but it still accepts comments

#11 @ravipatel
5 weeks ago

New PR: ​https://github.com/WordPress/wordpress-develop/pull/14209

@westonruter reviewed the earlier PR and the changes look good to him, but he suggested someone more familiar with the Users component take the review from here. Tests pass, and the case-sensitive fallback now has test coverage. Could a Users component maintainer take a look?

#12 @rejaulalomkhan
5 weeks ago

Patch Testing Report

Patch Tested: ​https://github.com/WordPress/wordpress-develop/pull/14209

Environment

  • WordPress: 7.2-alpha-63166-src
  • PHP: 8.3.35
  • Server: wordpress-develop local Docker environment (nginx), PHPUnit 9.6.38
  • Database: MySQL 9.7.2 (wp_users.user_email default utf8mb4_unicode_520_ci, and switched to utf8mb4_bin for testing)
  • Browser: N/A (WP-CLI and PHPUnit)
  • OS: Windows 11 (Docker Desktop / WSL 2)
  • Theme: N/A
  • MU Plugins: None activated
  • Plugins: None activated

Actual Results

  1. ✅ _ci collation: wp user create with ABc-TR@example.com when abc-tr@example.com exists is rejected (same as trunk, no regression).
  2. ✅ utf8mb4_bin collation, trunk: the case-variant user is created (bug reproduced).
  3. ✅ utf8mb4_bin collation, PR: creating the case-variant user is rejected with "Sorry, that email address is already used!".
  4. ✅ utf8mb4_bin collation, PR: wp user update changing another user's email to a case variant is rejected.
  5. ✅ Users list table: with two existing case-variant accounts, both rows show "Another user has this email address, possibly with different letter case." on both _bin and _ci collations; the unrelated admin row is not flagged.

Additional Notes

  • --group 66238: 10 tests pass on the PR (single site, multisite, and --order-by=reverse). With the PR's tests run against unpatched src, 6 of 10 fail (3 errors, 3 failures), so the tests cover the change.
  • --group user: passes on the PR (1359 tests); the 5 warnings are PHPUnit 10 deprecation notices that also appear on trunk.
  • Not tested: SQLite, and a visual check of the new list table CSS.
  • AI assistance: Claude Code was used to run the tests and the WP-CLI checks; results reviewed by me.

Supplemental Artifacts

None

​@westonruter commented on ​PR #14209:


5 weeks ago
#13

Per ​https://github.com/WordPress/wordpress-develop/pull/14053#pullrequestreview-5474743136:

The changes look good to me. But I don't have a lot of experience with users, so best if I let someone else pick this up the review from here.

​@ravipatel commented on ​PR #14209:


2 weeks ago
#14

Behavior note: on a case-sensitive collation, a user can no longer change only the letter case of their own email on the profile screen: send_confirmation_on_profile_email() compares with !==, and email_exists() now finds the user's own account and reports it as already used. Default case-insensitive installs already behave this way, so this makes both kinds of install consistent.

Note: See TracTickets for help on using tickets.