Add generic login errors setting to prevent username enumeration - #446
Open
polevaultweb wants to merge 3 commits into
Open
Add generic login errors setting to prevent username enumeration#446polevaultweb wants to merge 3 commits into
polevaultweb wants to merge 3 commits into
Conversation
Adds a new "Generic Login Errors" option under Login Settings that replaces specific error messages (invalid username, incorrect password) with a single generic message, preventing attackers from enumerating valid usernames. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…filter Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds an opt-in “generic login errors” feature to reduce username enumeration by normalizing certain authentication failures into a single message, plus an accompanying Playwright E2E test to validate the behavior.
Changes:
- Introduces an
authenticatefilter (priority 50) that replaces specific login-relatedWP_Errorcodes with a generic error message when enabled. - Adds an admin setting (
generic_login_errors) under the Login settings section to toggle the behavior. - Adds an E2E test to verify the same generic error is shown for nonexistent users and wrong passwords.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
tests/e2e/login.spec.ts |
Adds an E2E test that enables the new option and asserts generic errors for both invalid user and wrong password cases. |
includes/filters.php |
Adds a new authenticate filter callback that maps enumeration-prone error codes to a generic message when the setting is on. |
includes/admin/class-wpum-options-panel.php |
Registers the new checkbox setting in the Login settings panel. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+189
to
+193
| * @param WP_User|WP_Error $user | ||
| * @param string $username | ||
| * @param string $password | ||
| * | ||
| * @return WP_User|WP_Error |
| * | ||
| * @return WP_User|WP_Error | ||
| */ | ||
| function wpum_generic_login_errors( $user, $username, $password ) { |
Comment on lines
+247
to
+251
| array( | ||
| 'id' => 'generic_login_errors', | ||
| 'name' => __( 'Generic Login Error', 'wp-user-manager' ), | ||
| 'desc' => __( 'Replace specific login error messages with a generic message to prevent username enumeration.', 'wp-user-manager' ), | ||
| 'type' => 'checkbox', |
Comment on lines
+112
to
+114
| wpCli(`eval 'wpum_update_option("generic_login_errors", true);'`); | ||
|
|
||
| await page.goto(loginPage); |
Comment on lines
+139
to
+140
| wpCli(`eval 'wpum_update_option("generic_login_errors", false);'`); | ||
| }); |
Comment on lines
+120
to
+126
| const errorMessage = page.locator('.wpum-message.error'); | ||
| await expect(errorMessage).toBeVisible({ timeout: 5000 }); | ||
| const errorText = await errorMessage.textContent(); | ||
| expect(errorText).toContain('username or password you entered is incorrect'); | ||
| expect(errorText).not.toContain('not registered'); | ||
| expect(errorText).not.toContain('Unknown'); | ||
|
|
Comment on lines
+133
to
+137
| const errorMessage2 = page.locator('.wpum-message.error'); | ||
| await expect(errorMessage2).toBeVisible({ timeout: 5000 }); | ||
| const errorText2 = await errorMessage2.textContent(); | ||
| expect(errorText2).toContain('username or password you entered is incorrect'); | ||
| expect(errorText2).not.toContain('incorrect password'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
invalid_username,incorrect_password,invalid_email,email_only) with a single generic message: "The username or password you entered is incorrect"authenticateat priority 50 (after WPUM's own auth filter at 20 and WP core at 30)Test plan
🤖 Generated with Claude Code