Menu

Closing the WordPress REST API users route, then checking it with curl
📰

Closing the WordPress REST API users route, then checking it with curl

DEV Community: webdev·Calin V.·17 days ago
#d3C3fM1s
#devtowebdev#devto#dev#users#curl
Reading 0:00
15s threshold

/wp-json/wp/v2/users answers anonymous requests on a default WordPress install. The reply carries an id and a slug for each author.

That slug is the same value WordPress puts in the author archive address, /author/<slug>/ .

The REST API Handbook's FAQ is blunt about the obvious fix. It says you should not disable the REST API, because WordPress Admin functionality depends on it. So the work below is narrower: close one route, decide whether to require a login for the rest, then test both with curl.

See what your site answers today

Run these from a machine that isn't logged in to the site:

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

Enter fullscreen mode

Exit fullscreen mode

The second form matters. The Handbook says sites without pretty permalinks take the route as a rest_route query parameter, and that form also answers on sites that do have pretty permalinks.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.