A default WordPress install will tell an unauthenticated visitor exactly which accounts exist. Request /?author=1 and the canonical redirect sends you to /author/jsmith/. Request /wp-json/wp/v2/users and you get the author list as JSON. Core generates /wp-sitemap-users-1.xml and hands it to search engines. oEmbed responses carry author_name. And the login form says “Unknown username” when the account does not exist, which is a free oracle. Closing all of it takes one must-use plugin, one web server rule, and one pass over your user records. Do it — it removes the cheapest step from a credential-stuffing run. Then be honest with yourself about what you bought: friction, not a control.
What you’ll accomplish
- Separate
user_loginfromuser_nicenameanddisplay_name, so the name published on the front end is not the name typed into the login form. - Return 401 from
/wp-json/wp/v2/usersfor unauthenticated callers while keeping the block editor working for logged-in ones. - Stop core from generating the author sitemap, and strip the author fields out of oEmbed responses.
- Reject
?author=scans at nginx or Apache, before a PHP worker is spent on them. - Collapse every login failure into one message, so a wrong username and a wrong password look identical from outside.
Prerequisites
- WordPress 5.5 or newer. The core sitemaps feature, and the
wp_sitemaps_add_providerfilter that turns providers off, arrived in 5.5. - Shell access to the host, plus WP-CLI. Every command below runs against your own site.
- Write access to
wp-content/mu-plugins/. Must-use plugins load before regular plugins and cannot be deactivated from the dashboard by an attacker who gets a foothold in wp-admin. - Permission to edit the nginx server block or the site’s
.htaccess. - A staging copy. Two of these changes — the REST filter and the nicename rewrite — have visible effects on the editor and on live URLs.
- Examples use
example.com, an administrator with ID 1, and a login ofjsmith. Substitute your own throughout.
How it works
WordPress stores three separate strings per account and most operators never notice they are separate. user_login is what you type into the login form and it can never be changed through the dashboard. user_nicename is the URL-safe slug used to build /author/<slug>/. display_name is what the theme prints in a byline. At registration, core derives the nicename from the login and sets the display name to the login as well. That default is the whole problem: three different public surfaces end up echoing the credential.
The ?author=N redirect is the classic vector and it is not a bug. Passing author as a query variable makes WordPress run an author query; redirect_canonical() then sees that the request has a prettier permalink available and issues a 301 to /author/<nicename>/. The attacker never needs to load the archive — the Location header alone leaks the name, one integer at a time.
The REST API is the modern equivalent and it is faster: /wp-json/wp/v2/users returns every user who has published a post, with slug, name, and link in one response. It is unauthenticated-readable by design, because themes and headless front ends consume it. The core sitemaps feature added a third surface in 5.5, publishing the same author list as XML and inviting search engines to index it. oEmbed adds a fourth, since /wp-json/oembed/1.0/embed?url=<post-url> includes author_name and author_url in its payload.
Each of these has a supported filter or a server rule that closes it. None of them changes the fact that once an attacker has a name, the login form is the same login form. That is why the last section of this guide exists.
Step-by-step
-
Take a baseline against your own site. Record what each vector returns before you touch anything, so you can prove the change landed.
# Author archive redirect curl -sI 'https://example.com/?author=1' | grep -iE '^(HTTP|location)' # REST users collection curl -s 'https://example.com/wp-json/wp/v2/users' | jq -r '.[].slug' # Core author sitemap curl -so /dev/null -w '%{http_code}\n' 'https://example.com/wp-sitemap-users-1.xml'On an untouched install this prints something close to:
HTTP/2 301 location: https://example.com/author/jsmith/ jsmith editor2 200 -
Split the three name fields apart. List what you have, then rewrite the nicename and display name for every account that can log in.
wp user list --fields=ID,user_login,user_nicename,display_name wp user update 1 --user_nicename=editorial --display_name='Editorial Desk'Expect a table where
user_login,user_nicenameanddisplay_nameare identical, followed bySuccess: Updated user 1.This is the only step that reduces the value of the leak rather than hiding the leak. Everything after it is concealment. Note thatuser_loginitself stays as it is — WP-CLI will not change it, and changing it directly in the database breaks anything storing the login as a key. -
Filter the REST users endpoint for unauthenticated callers. Create
wp-content/mu-plugins/sh-user-enumeration.php. Therest_endpointsfilter rewrites the permission callback on the two user routes before the request is dispatched.<?php // Must-use plugin: close the user enumeration vectors. add_filter( 'rest_endpoints', function ( $endpoints ) { $routes = array( '/wp/v2/users', '/wp/v2/users/(?P<id>[\d]+)' ); foreach ( $routes as $route ) { if ( empty( $endpoints[ $route ] ) ) { continue; } foreach ( $endpoints[ $route ] as $i => $handler ) { $endpoints[ $route ][ $i ]['permission_callback'] = function () { return current_user_can( 'list_users' ); }; } } return $endpoints; } );Verify from outside, including the alternate query-string form of the REST route that some rules miss:
curl -s 'https://example.com/wp-json/wp/v2/users' | jq -r '.code, .data.status' curl -s 'https://example.com/?rest_route=/wp/v2/users' | jq -r '.code, .data.status'Both should now answer:
rest_forbidden 401The 401 is correct: core’s
rest_authorization_required_code()returns 401 when nobody is logged in and 403 when someone is but lacks the capability./wp/v2/users/meis a distinct route and is untouched, which matters in the next section. -
Turn off the author sitemap and strip oEmbed author fields. Append both filters to the same must-use plugin.
wp_sitemaps_add_providerreceives the provider object and its name; returning anything that is not aWP_Sitemaps_Providerprevents registration.add_filter( 'wp_sitemaps_add_provider', function ( $provider, $name ) { return ( 'users' === $name ) ? false : $provider; }, 10, 2 ); add_filter( 'oembed_response_data', function ( $data ) { unset( $data['author_name'], $data['author_url'] ); return $data; } );Check both, using any published post URL of your own:
curl -s 'https://example.com/wp-sitemap.xml' | grep -c 'wp-sitemap-users' curl -so /dev/null -w '%{http_code}\n' 'https://example.com/wp-sitemap-users-1.xml' curl -s 'https://example.com/wp-json/oembed/1.0/embed?url=https://example.com/hello-world/' | jq 'has("author_name")'0 404 falseThe users entry is gone from the sitemap index, the users sitemap itself is no longer generated, and the oEmbed payload has lost its author fields.
-
Reject
?author=scans at the web server. Doing this in PHP works, but it still costs a worker per probe. Rejecting at the edge costs nothing. For nginx, inside the server block:if ($arg_author) { return 403; }For Apache, near the top of
.htaccess, above the WordPress rewrite block:<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{QUERY_STRING} (^|&)author=[0-9] [NC] RewriteRule ^ - [F,L] </IfModule>Reload the server, then re-run the first baseline command:
curl -sI 'https://example.com/?author=1' | grep -iE '^(HTTP|location)'HTTP/2 403No
Locationheader means no name. If you have no legitimate use for author archives at all — most business sites do not — add the removal in PHP as well, so the pretty permalink form stops resolving too:add_action( 'template_redirect', function () { if ( is_author() ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } ); -
Collapse the login error messages. Core distinguishes
invalid_usernamefromincorrect_passwordand prints different text for each. Thelogin_errorsfilter replaces whatever was about to be shown.add_filter( 'login_errors', function () { return 'The username or password you entered is not correct.'; } );Test it once against your own login form with a name that does not exist, and once with a real account and a deliberately wrong password:
curl -s -X POST 'https://example.com/wp-login.php' \ --data 'log=not-a-real-account&pwd=wrong' | grep -o 'login_error[^<]*'Both requests should render the same string. Before the filter, the first returned text naming the unknown username and the second named the account whose password was wrong. Note that the lost-password form has its own messages; core has already made that flow generic, so there is nothing to change there.
Validate it works
Run the whole set in one pass from a machine that is not logged in. Every line should match the second column.
curl -sI 'https://example.com/?author=1' | head -1 # 403
curl -sI 'https://example.com/author/editorial/' | head -1 # 404
curl -s 'https://example.com/wp-json/wp/v2/users' | jq -r '.data.status' # 401
curl -s 'https://example.com/?rest_route=/wp/v2/users' | jq -r '.data.status' # 401
curl -so /dev/null -w '%{http_code}\n' 'https://example.com/wp-sitemap-users-1.xml' # 404
curl -s 'https://example.com/wp-json/oembed/1.0/embed?url=https://example.com/hello-world/' | jq 'has("author_name")' # false
Then load a published post in a browser and read the byline. If it still shows jsmith, the theme is printing user_login or the nicename directly rather than display_name, and step 2 did not reach it.
Troubleshooting
The block editor’s author dropdown is empty. This is the most common casualty. The editor queries the users collection to populate the author selector, and your permission callback now demands list_users — a capability Editors and Authors do not have. If your workflow needs those roles to reassign authorship, relax the callback to is_user_logged_in() && current_user_can( 'edit_posts' ) instead. That still blocks unauthenticated enumeration, which was the point. The narrower approach is covered in restricting unauthenticated REST API access.
An SEO plugin puts the author sitemap back. Yoast, Rank Math and All in One SEO replace the core sitemap entirely, so wp_sitemaps_add_provider never runs for their output. Confirm with curl -s https://example.com/sitemap_index.xml and look for an author sitemap entry. Each plugin has its own switch — an author archives toggle in the search appearance settings, usually. Turn it off there; the core filter is not going to reach it.
The ?author=1 redirect still fires. Almost always a cache serving the 301 it stored before the rule went in. Purge the page cache and any CDN, then retest with a cache-busting query string. If it persists, check that the nginx if block is in the server context and not inside a location that the request never enters, and that no earlier location block matched first.
A headless front end genuinely needs the users endpoint. Do not remove the filter. Have the front end authenticate — an application password on a dedicated read-only account is the simplest route — and the callback will pass. If the consumer cannot authenticate, register your own route that returns only the fields it needs, with no slug, rather than reopening the core collection.
Old author URLs are indexed and now return 404. Changing user_nicename changes the archive permalink, and WordPress does not redirect the old one. Either accept the 404s and submit a removal request in Search Console, or add a redirect from the old slug to the site’s team page at the web server before you make the nicename change. Do this in that order — the URLs are much easier to enumerate from your own analytics than to guess afterwards.
When this is the wrong approach
Everything above is obscurity. It is worth doing, and it is not a control.
A determined attacker gets your usernames anyway. Comment authors are printed in the markup. Contributor bylines appear in RSS feeds and in structured data your SEO plugin emits. WordPress leaves the account list intact in XML-RPC responses on sites that have not disabled it. Past job postings, LinkedIn, git commit metadata on a public theme repository, and the archived copy of the site from before you hardened it are all outside your reach. Even the login form will still confirm a valid account through response timing on many hosts, because a real account triggers a password hash comparison and a fake one does not.
More to the point, an attacker running a credential-stuffing campaign is not enumerating you at all. They are replaying pairs from a breach dump against wp-login.php and xmlrpc.php as fast as your host will take them. Enumeration hardening does not slow that down by a single request.
The controls that do are two: two-factor authentication on every admin account, which makes a correct password insufficient, and rate limiting with lockout on the login endpoints, which makes the attempt volume uneconomic. Deploy those first. Treat the work in this guide as what it is — closing the free reconnaissance step, cutting scanner noise out of your logs, and removing the accidental publication of credentials as bylines. If you have a fixed budget of an afternoon and none of it has gone to 2FA yet, spend it there instead and come back to this.
The authoritative references are the WordPress security APIs and the REST API handbook, which document the filters used here and the permission model behind them.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.