Sample alert How it works Coverage PENTEST METHODOLOGY DOCS PRICING FAQ MCP CONTACT LOG IN SCAN MY APP →

WordPress /wp-json/wp/v2/users leaks usernames: how to fix

FIX / WP USER ENUMERATION / 9 MIN READ

WordPress lists author usernames to anyone through the /wp-json/wp/v2/users endpoint and the /?author=1 redirect. Restrict the endpoint to logged-in users, stop the redirect, and change any author slug that equals a login name. This is a low risk alone. It becomes a high risk when it meets weak passwords or an open login form.

This guide shows how to confirm the problem and how to fix it with short PHP code. It also shows how to know when the risk is more than low.

What does WordPress expose?

A default WordPress site shows the names of its authors in three places.

  1. The REST API. The /wp-json/wp/v2/users endpoint lists users. The REST API handbook says that a visitor can see public data of users who have published posts. The data includes the numeric ID, the display name, and the slug.
  2. The author redirect. A request to /?author=1 redirects to /author/<slug>/. The slug shows in the address. An attacker can change the number from 1 up to find all authors.
  3. Other places. The author sitemap, the author archive pages, the post feed and the oEmbed data can also show the author name or slug.

The slug field is the user_nicename of the user. WordPress makes it from the login name when it creates the user. If you never changed it, the slug is the login name. The attacker then knows a valid login.

AI tools and quick installs often leave this setting as it is. The tool makes the site work. It does not make a decision about author data.

Note that a visitor sees only users who have published posts. An admin account that never posted is not in the list. The slug can also differ from the login name. Do not assume that the list is complete or exact. Test your own site.

How do I confirm that my site exposes usernames?

Test as a visitor. Use curl with no cookie.

  1. Request the users endpoint.
curl -s "https://your-site.example/wp-json/wp/v2/users?per_page=100"
  1. Read the answer. A JSON list with id, name and slug fields means that the site exposes users. A 401 or 403 answer, or an empty list, is the correct result.
  2. If you have jq, print only the fields that matter.
curl -s "https://your-site.example/wp-json/wp/v2/users?per_page=100" | jq '.[] | {id, name, slug}'
  1. Request a single user.
curl -s "https://your-site.example/wp-json/wp/v2/users/1"
  1. Test the author redirect. The -I flag prints only the headers.
curl -sI "https://your-site.example/?author=1"
  1. Read the Location header. A value such as https://your-site.example/author/admin/ shows the slug. A 404 status or a redirect to the home page is the correct result.
  2. Test the next numbers: ?author=2, ?author=3. A script can do this in a second.
for i in 1 2 3 4 5; do
  curl -sI "https://your-site.example/?author=$i" | grep -i '^location'
done
  1. If the REST API uses plain permalinks on your site, the path is /?rest_route=/wp/v2/users. Test that address too.
curl -s "https://your-site.example/?rest_route=/wp/v2/users"
  1. Check the author sitemap.
curl -s "https://your-site.example/wp-sitemap-users-1.xml"

A response with author URLs means that the sitemap lists the slugs. Fix each place that answers.

How do I restrict the users endpoint to logged-in users?

Remove the users routes for visitors. Use the rest_endpoints filter. The filter reference describes it. Put the code in a small plugin or in a must-use plugin. A theme functions.php file is not the best place, because the code is lost when you change the theme.

  1. Create the file wp-content/mu-plugins/restrict-users-endpoint.php.
  2. Add this code.
<?php
/**
 * Plugin Name: Restrict users endpoint
 */

defined( 'ABSPATH' ) || exit;

add_filter( 'rest_endpoints', 'myrestrict_hide_user_routes' );

function myrestrict_hide_user_routes( $endpoints ) {
	if ( is_user_logged_in() ) {
		return $endpoints;
	}

	unset( $endpoints['/wp/v2/users'] );
	unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );

	return $endpoints;
}
  1. Run the curl tests again. The endpoint must now answer with a 404 status and the code rest_no_route.

The filter keeps the routes for any logged-in user. This protects the block editor, which needs the list of users. A subscriber can then still read the list. If you have untrusted logged-in users, such as members of a public site, use a stronger check:

if ( current_user_can( 'list_users' ) ) {
	return $endpoints;
}

The capability list_users belongs to administrators by default. Test the editor with an editor account after you add this check. If an editor cannot pick an author, use edit_others_posts instead.

Caution: Some themes and plugins call the users endpoint from the front end, for example to show an author list. They stop working after this change. Test the pages that show author names.

You do not need a plugin for this. If you prefer a plugin, choose one that lets you set the rule, and test it with the same curl command. Do not trust the setting alone.

How do I stop the author redirect?

The redirect comes from the ?author= query. Block it for visitors. Add this code to the same must-use plugin.

add_action( 'template_redirect', 'myrestrict_block_author_query', 1 );

function myrestrict_block_author_query() {
	// phpcs:ignore WordPress.Security.NonceVerification.Recommended
	if ( ! isset( $_GET['author'] ) || is_user_logged_in() ) {
		return;
	}

	wp_safe_redirect( home_url( '/' ), 301 );
	exit;
}

The code runs before the default redirect, because it uses priority 1. A visitor with ?author=1 goes to the home page. The code does not change normal author archive pages at /author/<slug>/.

If your site does not need author archive pages, turn them off. Many SEO plugins have this option. You can also remove the sitemap list of users:

add_filter( 'wp_sitemaps_add_provider', 'myrestrict_remove_users_sitemap', 10, 2 );

function myrestrict_remove_users_sitemap( $provider, $name ) {
	return 'users' === $name ? false : $provider;
}

A page cache can serve the old redirect. Clear the cache after the change. If a web server rule or a CDN rule handles the redirect before WordPress, add the rule there. In Nginx, for example, you can return 403 for the query:

if ($args ~* "(^|&)author=\d+") {
    return 403;
}

Test with the curl command again.

How do I make the display name different from the login name?

Change the slug and the public name of each author. Then the public data does not give a valid login.

  1. Open Users in the admin area. Open the profile of an author.
  2. Set Nickname to a name that is not the login name.
  3. In Display name publicly as, select the nickname.
  4. Save the profile.

The slug (user_nicename) does not change when you change the nickname. Change it with WP-CLI:

wp user update 1 --user_nicename="editor-team"

Use a name that is not the login name and not a guess, for example not admin. Check the result:

wp user get 1 --fields=ID,user_login,user_nicename,display_name

Be careful with author archive URLs. The old /author/<old-slug>/ address stops working. If other sites link to it, add a redirect.

Do not use admin as the login name for the main account. If your account has this name, create a new administrator with a different name. Log in with it. Then delete the old account and assign its posts to the new one. WordPress does not let you rename a login name in the profile screen.

Also check the login form. By default, WordPress gives a different error for a wrong user name and a wrong password. The difference tells an attacker if the name exists. You can show one message for both:

add_filter( 'login_errors', function () {
	return 'The login details are not correct.';
} );

Is this a high risk or a low risk?

Alone, a username is low risk. A username is not a secret in many systems. Many sites show author names on purpose. You still must not give attackers a free list of valid logins.

The risk becomes high when you add one of these:

  • Weak passwords. A short or common password breaks fast in a password spray.
  • No limit on login attempts. The attacker can try many passwords for each name. Read the brute force guide.
  • An open XML-RPC endpoint. The xmlrpc.php file lets an attacker test many passwords in one request. Block it if you do not use it.
  • An admin account that is also an author. The attacker gets the most powerful login name.
  • No two-factor login. A leaked password alone gives access.
  • Predictable IDs. The numeric IDs let an attacker count all users. The guide on sequential IDs explains this risk.
  • An email address as a login name. The slug can then leak a personal address.

Fixing the username leak is one small step. These controls protect the login:

  1. Use long, unique passwords. Use a password manager.
  2. Add two-factor login for all admin and editor accounts.
  3. Limit the number of failed logins for each IP address and each user.
  4. Block xmlrpc.php if no tool needs it.
  5. Keep WordPress, themes and plugins up to date.
  6. Read the log of your login page. Many failed logins for many names in a short time show an attack.

How do I check if someone already used the names?

Read the logs of your web server and your login page.

  1. Search the access log for requests to /wp-json/wp/v2/users and ?author=. Many requests from one IP address with growing numbers show a scan.
  2. Search for many POST requests to /wp-login.php and /xmlrpc.php.
  3. Check the list of administrators. Look for users that you do not know.
wp user list --role=administrator --fields=ID,user_login,user_email,user_registered
  1. Check for new plugins, new PHP files in wp-content/uploads, and changed core files.
wp core verify-checksums
  1. If a name appeared in a scan, change the password for that user. Add two-factor login.

When should I get help?

Get help in these cases:

  • The logs show a successful login from an IP address that you do not know.
  • You find a new admin user or a new plugin that you did not add.
  • wp core verify-checksums reports a changed core file.
  • The site sends spam or redirects visitors to other sites.

If you cannot tell if the site is clean, restore a clean backup, change all passwords, and ask a security engineer to review the site. Scan the live site again after the fix. The users endpoint and the author redirect must give no username.

Common questions

Is the exposed username a serious problem?
Alone, it is low risk. A username is not a password. It gives an attacker one half of a login, so it makes brute force and password spray attacks easier.
Will the fix break my block editor or my theme?
No, if you restrict the endpoint only for visitors. Logged-in users keep access. Test the editor and any theme that lists authors with the REST API.
Does a security plugin do this for me?
Many security plugins have an option for it. Check that the option works with the curl test in this guide. A setting that you cannot test is not proof.
Do I need to hide the username if I use a strong password and two-factor login?
It is still good to hide it. A strong password and a second factor make a break-in hard. Hiding the name removes free information and reduces noise in your logs.
Is the slug always the same as the login name?
No. WordPress creates the slug from the login name when the user is made. You can change the slug later. Then the public name no longer equals the login name.

Check your user endpoints

A VibeEval scan requests /wp-json/wp/v2/users and the author redirect on your live site without a login, and reports the usernames that they return.

14-day free trial · Cancel anytime

SCAN YOUR APP →