WordPress user enumeration is getting a site to list or confirm its usernames without logging in. A default install does it in five places: ?author=N redirects, the REST API users endpoint, the users sitemap, oEmbed responses, and the messages on the login and lost-password forms.
Most guides cover the first two and stop. This one shows what each place returns, why an admin who has never published a post usually shows up anyway, and how to test every fix with curl on a copy of the site before it goes anywhere near production.
Is user enumeration actually a vulnerability?
Not in WordPress's own view. The core handbook's page on reporting security vulnerabilities says it directly: "The WordPress project doesn't consider usernames or user IDs to be private." (fetched 2026-11-08).
That is a fair position, and it matters for what you do next. A known username only helps an attacker who can then guess the password.
So the fixes in this post are hygiene, not the defence.
The defence is a long unique password, two-factor authentication on admin accounts, and rate limiting on wp-login.php and xmlrpc.php. If you only have time for one thing, do those.
Hiding usernames is still worth doing on sites where the login is a real person's name or email prefix. It removes half the guesswork from password spraying, and it stops your client's staff list being one request away.
The five places WordPress gives out usernames
Everything below was read from the WordPress 7.1.4 source.
One distinction runs through all of it: user_login is what people log in with, and user_nicename is the URL slug. WordPress builds the nicename from the login when the account is created, so on most sites they are the same string.
| Where | What it returns | Who it covers |
|---|---|---|
/?author=N |
A 301 to /author/<nicename>/ |
Users with at least one published post of any type |
/wp-json/wp/v2/users |
id, name, slug (the nicename), link |
Users with a published post in any REST-enabled post type |
/wp-sitemap-users-1.xml |
Author archive URLs, so nicenames | Users with a published post in a public post type, not counting pages |
/wp-json/oembed/1.0/embed?url=… |
author_name (display name) and author_url (nicename) |
The author of whichever post you ask about |
wp-login.php |
"The username x is not registered" vs "The password you entered for the username x is incorrect" | Anyone you guess |
Author archives: ?author=N
redirect_canonical() turns /?author=2 into a 301 to /author/jane/, but only when that user has a published row in wp_posts. The query does not check the post type, so a published page, menu item or block counts.
What happens when the user has nothing published is the part guides miss. WordPress deliberately does not 404 an author archive for a real member of the site, so /?author=2 returns a 200 empty archive instead.
That empty archive still prints author-jane author-2 in the <body> class on most themes, and the display name in the <title>.
An ID that does not exist gets a 404. So the status code alone confirms which IDs are real accounts.
The REST API: /wp-json/wp/v2/users
For a logged-out visitor, the users endpoint lists anyone with a published post in any post type that has show_in_rest enabled. In core that includes wp_global_styles, wp_navigation, wp_template, wp_block and nav_menu_item, not just posts and pages.
Asking for a single user is an oracle on its own. /wp-json/wp/v2/users/7 returns a 404 with rest_user_invalid_id when no user 7 exists, and a 401 with rest_user_cannot_view when one does but has nothing published.
The search parameter is the one that undoes the usual advice.
For a visitor without the list_users capability, core still searches the user_login column. If you changed someone's slug so it no longer matches their login, /wp-json/wp/v2/users?search=jsmith will still return them when their login contains jsmith, as long as they are in the list at all.
The users sitemap
Since WordPress 5.5, /wp-sitemap-users-1.xml lists the author archive URL of every user with a published post in a public post type. Pages and attachments are excluded, so it is narrower than the REST list, but every <loc> ends in a nicename.
oEmbed
Every public post has an oEmbed endpoint. Its JSON carries author_name, which is the display name, and author_url, which is the author archive link with the nicename in it.
It reveals no more than the post page does on most themes. It is worth knowing about because it is the one place the post's author is exposed even on a theme that hides bylines.
Login and lost-password messages
wp_authenticate_username_password() has separate errors for an unknown username and a wrong password, and wp_authenticate_email_password() does the same for email addresses. So the login form confirms both usernames and emails.
The lost-password form says "There is no account with that username or email address." for an unknown account. For a real one it redirects to wp-login.php?checkemail=confirm, which is a confirmation even if you change the message.
XML-RPC is not on the list, for a different reason. Its login failure is a single "Incorrect username or password." for both cases, so it confirms nothing.
Its risk is system.multicall, which lets one request carry many password attempts. Our XML-RPC post covers turning it off.
Why the admin who never wrote a post still shows up
People check /wp-json/wp/v2/users, expect to see the editors who write posts, and find the site owner's admin account in the list too. The block editor is the usual reason.
The first time anyone opens the block editor or the Site Editor under a theme, WordPress creates a wp_global_styles post for that theme. It is created with post_status set to publish, and with no author passed, so the author is whoever opened the editor.
That one hidden row makes the admin a user with a published post, as far as the REST users endpoint and ?author=N are concerned. Saving a navigation menu, a synced pattern or a template does the same.
You can see this on any site with WP-CLI. This lists who owns published rows, grouped by type:
wp db query "SELECT post_author, post_type, COUNT(*) AS n
FROM $(wp db prefix)posts WHERE post_status = 'publish'
GROUP BY post_author, post_type ORDER BY post_author"
If an admin's ID appears only next to wp_global_styles, nav_menu_item or wp_navigation, that is why they are listed.
Reassigning those rows only moves the problem to another account. Restricting the endpoints is the fix.
Test what your site leaks, in six requests
Run these against a copy, not production, so you can change things and run them again.
Set SITE to the copy's URL. On a site with plain permalinks, replace /wp-json/ with /?rest_route=/.
SITE=https://your-copy.example
# 1. Author IDs: 301 + Location = has posts, 200 = real user, 404 = no such user
for id in 1 2 3 4 5; do
printf '%s ' "$id"
curl -s -o /dev/null -w '%{http_code} %{redirect_url}\n' "$SITE/?author=$id"
done
# 2. The REST list
curl -s "$SITE/wp-json/wp/v2/users" | jq -r '.[] | "\(.id) \(.slug) \(.name)"'
# 3. Single users: rest_user_invalid_id = no such user, rest_user_cannot_view = exists
for id in 1 2 3; do curl -s "$SITE/wp-json/wp/v2/users/$id" | jq -r '.code // .slug'; done
# 4. Login search, which ignores the slug
curl -s "$SITE/wp-json/wp/v2/users?search=admin" | jq -r '.[].slug'
# 5. The users sitemap
curl -s "$SITE/wp-sitemap-users-1.xml" | grep -o '<loc>[^<]*'
# 6. oEmbed for one post
curl -s "$SITE/wp-json/oembed/1.0/embed?url=$SITE/hello-world/" | jq -r '.author_name, .author_url'
For any ID that returned a 200 in step 1, check what the empty archive prints:
curl -s "$SITE/?author=2" | grep -o 'author-[a-z0-9_-]*' | sort -u
Write down what each request returns before you change anything. That is the baseline the fixes are measured against.
Fixes that hold up
Put these in one file in wp-content/mu-plugins/, so a theme switch or a deactivated plugin cannot turn them off. Our must-use plugins post explains the loading rules.
<?php
/**
* Plugin Name: Limit user enumeration
*/
// REST: remove the users list and single-user routes for logged-out requests only.
// The block editor sends a nonce, so it keeps its author dropdown.
add_filter( 'rest_endpoints', function ( $endpoints ) {
if ( ! is_user_logged_in() ) {
unset( $endpoints['/wp/v2/users'], $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
}
return $endpoints;
} );
// ?author=N: stop the scan before redirect_canonical() runs at priority 10.
add_action( 'template_redirect', function () {
if ( isset( $_GET['author'] ) ) {
wp_safe_redirect( home_url( '/' ), 301 );
exit;
}
}, 1 );
// Sitemap: drop the users provider.
add_filter( 'wp_sitemaps_add_provider', function ( $provider, $name ) {
return 'users' === $name ? false : $provider;
}, 10, 2 );
// oEmbed: report the site as the author, as core does for posts without one.
add_filter( 'oembed_response_data', function ( $data ) {
$data['author_name'] = get_bloginfo( 'name' );
$data['author_url'] = home_url();
return $data;
} );
// Login screen: one message for every failure.
add_filter( 'login_errors', function () {
return '<strong>Error:</strong> The username, email address or password is incorrect.';
} );
Three details in there are easy to get wrong.
The template_redirect priority matters. Core hooks redirect_canonical() at the default priority of 10, so a snippet added at 10 from a theme runs after it, and the 301 with the nicename has already been sent.
The REST filter only applies to logged-out requests on purpose. Removing /wp/v2/users for everyone breaks the author selector in the editor, which loads users with who=authors.
The login_errors filter replaces every message on the login screen, including the empty-field messages and the cookies warning. That is the price of a single message.
It also does not hide the lost-password redirect, which only rate limiting really addresses.
What this leaves alone is /author/<nicename>/, so multi-author blogs keep their author pages. If the slug giving away the login is the problem, change the slug instead:
wp user update 2 --user_nicename=jane-writer
That is a different field from the login, which WP-CLI refuses to change.
Our username post covers renaming the login itself. Remember that the REST search in step 4 still matches the login, which is one more reason the REST filter above is worth having.
Why test this on a copy first
Every fix here is small, and each one can break something you did not know depended on it. A headless front end, a membership plugin or a mobile app may call /wp/v2/users without being logged in.
Security plugins are the other trap. Many already offer an "author scan" or "REST API" switch, and two layers redirecting the same request can produce a loop or an editor that will not load.
The workflow that catches both is short.
Make a copy of the live site with the Cloner, which only reads production, then SSH into the copy and run the six requests to get a baseline. Add the mu-plugin, run them again, then open the block editor and change a post's author to confirm nothing broke.
One honest limit: a sandbox does not have your host's firewall, CDN rules or login rate limiting in front of it. It tells you what WordPress itself returns.
Run requests 1 and 2 against production once afterwards, because a host-level rule can change the answer in either direction.
For agencies with many client sites, the baseline script is the useful artefact. Run it against each site's copy, keep the output, and you have a record of what each one exposed and what changed.
