Wiki / WordPress and CMS

Warning: WordPress user list via the REST APIpublic names and IDs

Anyone can open /wp-json/wp/v2/users and get the ID, display name and slug of every user who has published something, and the slug is normally the login name. No passwords or e-mail addresses are in there, so it is not urgent, but it hands a password guesser half of the login pair.

What it does not mean. It is not a WordPress bug: the project does not consider usernames private and keeps this address public on purpose. Nor does it mean the whole REST API should be closed: the line “/wp-json/ responds with HTTP 200” is normal for a WordPress site.

Aleksandr IzmalkovFacts checked:

In our report
Warning (yellow); category “Publicly accessible sensitive paths”, weight 2.0 (the highest)
Time to fix
10 minutes
Can it break things
Yes, if you close it for logged-in users too: the editor loses its author list

How to fix it

What we saw on a test WordPress 7.1.4: the fields id, name, url, description, link, slug, avatar_urls, meta. slug was the login with dots turned into hyphens (jonas.admin → jonas-admin), name equalled the login until another display name was set, and avatar_urls held the SHA-256 hash of the e-mail address. Users who had published nothing were not listed.

WordPress (tested on 7.1.4, PHP 8.4), file wp-content/mu-plugins/close-users-api.php

<?php
add_filter( 'rest_endpoints', function ( $endpoints ) {
    if ( is_user_logged_in() ) {
        return $endpoints;
    }
    unset( $endpoints['/wp/v2/users'] );
    unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
    return $endpoints;
} );

A visitor gets 404 rest_no_route at /wp-json/wp/v2/users, /users/1 and /?rest_route=/wp/v2/users; a logged-in editor (cookie and nonce) and an application password still get the list. The rest_endpoints filter has existed since WordPress 4.4.

nginx (tested on 1.26.3), in the `server` block

set $users_api 0;
if ($request_uri ~* "/wp-json/wp/v2/users|rest_route=(/|%2F)wp(/|%2F)v2(/|%2F)users") {
    set $users_api 1;
}
if ($http_cookie ~ "wordpress_logged_in_") {
    set $users_api 0;
}
if ($users_api) {
    return 404;
}

Returned 404 for /wp-json/wp/v2/users, /users/1, ?rest_route=/wp/v2/users and its %2F form; /wp-json/ and /wp-json/wp/v2/posts stayed 200. The rule only checks that a wordpress_logged_in_ cookie is present, and anyone can send one, so use it together with the PHP snippet, not instead of it.

Apache (tested on 2.4.59), .htaccess above `# BEGIN WordPress`

RewriteEngine On
RewriteCond %{HTTP_COOKIE} !wordpress_logged_in_
RewriteCond %{REQUEST_URI} /wp-json/wp/v2/users [NC,OR]
RewriteCond %{QUERY_STRING} rest_route=(/|%2F)wp(/|%2F)v2(/|%2F)users [NC]
RewriteRule ^ - [R=404,L]

Needs mod_rewrite. Same results and the same cookie caveat as nginx.

Terminal: before the fix /wp-json/wp/v2/users returns two users with the slugs jonas-admin and ruta-redaktore; after it a visitor gets rest_no_route 404 while a logged-in user still sees the list
A test WordPress 7.1.4 before and after the rest_endpoints snippet. The users are made up.

How to check

curl -s -o /dev/null -w "%{http_code}\n" https://example.com/wp-json/wp/v2/users

Expected

404

200 with a JSON list means the address is open; 401 means the whole API requires a login.

What can break

  • Without the is_user_logged_in() line the block editor loses its author picker: it requests /wp/v2/users?who=authors.
  • Visitor requests with _embed get an error in place of the author: /wp/v2/posts?_embed=author returned rest_no_route in _embedded.author. A headless front end or app that shows author names anonymously will lose them.
  • The server rules let requests through by cookie only: an app that signs in with an application password has no cookie and gets 404 from nginx or Apache.
  • The login name shows up elsewhere too, for example through /?author=1; that line has its own wiki page.

Possible values

How much to close: three routes, all tried on WordPress 7.1.4.

What you doWhat a visitor getsWhen to choose it
Close only /wp/v2/users (snippet above)404 for the user list, everything else worksRecommended
Whole REST API for logged-in users only (rest_authentication_errors, snippet in the WordPress REST API FAQ)401 everywhere: /wp-json/, posts, oEmbedOnly if nothing on the site calls the API from the visitor's browser
Close nothing, change the slug: wp user update 1 --user_nicename=redakcija --display_name="Redakcija"The list stays but shows redakcija, not the loginWhen apps or a headless front end need the endpoint

Our data

239

of 73,386 inspected .lt websites (0.33%) return a user list at this address. Dataset, 16 November 2026

Sources

Next