Skip to content

Add generic login errors setting to prevent username enumeration - #446

Open
polevaultweb wants to merge 3 commits into
developfrom
fix/generic-login-errors
Open

Add generic login errors setting to prevent username enumeration#446
polevaultweb wants to merge 3 commits into
developfrom
fix/generic-login-errors

Conversation

@polevaultweb

Copy link
Copy Markdown
Contributor

Summary

  • Adds a new Generic Login Errors checkbox under Settings → Login Settings
  • When enabled, replaces specific login error messages (invalid_username, incorrect_password, invalid_email, email_only) with a single generic message: "The username or password you entered is incorrect"
  • Prevents username enumeration via login error message differentiation
  • Hooks into authenticate at priority 50 (after WPUM's own auth filter at 20 and WP core at 30)

Test plan

  • Enable the setting in WPUM → Settings → Login Settings → Generic Login Errors
  • Try logging in with a non-existent username — error should say "username or password you entered is incorrect"
  • Try logging in with a valid username but wrong password — same generic error
  • Disable the setting — errors should revert to WordPress defaults (specific messages)
  • E2E test covers both scenarios

🤖 Generated with Claude Code

polevaultweb and others added 3 commits June 25, 2026 11:55
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>

Copilot AI 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.

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 authenticate filter (priority 50) that replaces specific login-related WP_Error codes 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 thread includes/filters.php
Comment on lines +189 to +193
* @param WP_User|WP_Error $user
* @param string $username
* @param string $password
*
* @return WP_User|WP_Error
Comment thread includes/filters.php
*
* @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 thread tests/e2e/login.spec.ts
Comment on lines +112 to +114
wpCli(`eval 'wpum_update_option("generic_login_errors", true);'`);

await page.goto(loginPage);
Comment thread tests/e2e/login.spec.ts
Comment on lines +139 to +140
wpCli(`eval 'wpum_update_option("generic_login_errors", false);'`);
});
Comment thread tests/e2e/login.spec.ts
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 thread tests/e2e/login.spec.ts
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');
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