Should You Block the REST API for Logged-Out Visitors?
Every WordPress site answers requests at /wp-json/. That is the REST API, and it is on for everyone by default, including visitors who are not logged in. Open yoursite.com/wp-json/wp/v2/users in a private window and you
Every WordPress site answers requests at /wp-json/. That is the REST API, and it is on for everyone by default, including visitors who are not logged in. Open yoursite.com/wp-json/wp/v2/users in a private window and you will often see a list of the people who publish on the site. That is usually the moment someone decides to switch the whole thing off for logged-out visitors.
Sometimes that is the right call. Often it breaks something nobody connects to the change until a customer complains. I built SlimPress so that every switch says what it might break, and this one is marked Careful for good reason. Here is how to decide.
What the REST API does for logged-out visitors
When you are logged in, the block editor and a lot of wp-admin talk to the REST API constantly. Blocking it for logged-out visitors leaves that alone. What it affects is everything a visitor's browser, or another server, asks for without a login. On a typical site that can include:
- Contact forms that submit through the REST API instead of a normal page reload.
- Booking and ticketing plugins that load availability or reserve a slot in the background.
-
WooCommerce blocks, such as the cart and checkout blocks, which use WooCommerce's Store API under
/wp-json/. - Headless or decoupled front ends that fetch all their content from it.
- Embeds, when other sites ask yours for the preview card of a post.
The SlimPress readme names the first three as the most common casualties: contact forms, booking plugins and WooCommerce blocks.
Why people want it closed
The honest reasons are narrower than many guides suggest. The REST API only shows logged-out visitors what is already public, with one exception people notice: the user list, which exposes author usernames. Beyond that, closing it reduces how much of your site's structure is readable by scripts and shrinks the number of public endpoints a bot can poke at. It is a reasonable piece of tidying. It is not a security fix on its own, and I would not treat it as one.
If usernames are your actual concern, there is a smaller change. SlimPress has a separate switch for the REST user list, and another for ?author= username lookups in the Content & URLs group. Those close the username leak without touching anything your forms or shop depend on.
Step 1: find out what uses it
- Open your site in a private window, so you are logged out.
- Open the browser's developer tools on the Network tab and filter for
wp-json. - Do the things a visitor does: submit the contact form, add a product to the cart, open checkout, pick a booking slot, use the search.
- Write down the first part of the path after
/wp-json/for each request. That part is the namespace, the name a plugin registers its endpoints under. Core useswp/v2; plugins use their own.
If the list is empty after a realistic visit, nothing on your front end needs the REST API for visitors. If it is not empty, you now have your allowlist.
Step 2: switch it off with an allowlist
- Install and activate SlimPress. Activation changes nothing; every switch starts off.
- Go to Settings → SlimPress and open the APIs & connections group.
- Turn on Disable the REST API for logged-out visitors.
- Add the namespaces you wrote down in step 1 to its allowlist, so those plugins keep working for visitors.
- Save.
SlimPress also warns you when an active plugin is known to need something you are about to switch off, so read the notice before you save if one appears.
Step 3: test it as a visitor
Go back to the private window and repeat the same visit: the form, the cart, checkout, a booking. Keep the Network tab open. A blocked request shows up there as an error response from /wp-json/. If one appears for something you need, its namespace belongs on the allowlist. Then open /wp-json/wp/v2/users again to confirm the user list is no longer readable while logged out.
Test while logged out. If you only check while logged in as an admin, everything will look fine, because logged-in requests are not what this switch affects.
What can break, and when another approach is better
The failure mode here is quiet. A form that sends through the REST API may look like it submitted and then show an error, or do nothing. A checkout block may refuse to load. Nobody gets an email about it. That is why I would only use this switch after the visitor test above, and repeat the test after installing any new plugin that does something on the front end.
Some cases where I would not use it at all:
- Headless sites. If your front end is a separate app reading from WordPress, the REST API is the site. SlimPress has a Headless preset for that setup, and it skips anything an active plugin relies on.
- Shops built on the WooCommerce cart and checkout blocks, unless you are comfortable maintaining the allowlist as WooCommerce changes.
- When the goal is stopping attacks. Rate limiting at your host, a firewall or a security plugin does that job better than hiding endpoints.
If all you want is this one change, a few lines of code in a small custom plugin can do it too, using WordPress's rest_authentication_errors filter. SlimPress makes more sense when the REST API is one of several core features you want to review with the risks written next to each switch.
How to undo it
SlimPress keeps the last 10 versions of its settings. If something breaks, open Tools → Undo a change and restore the version from before. To find the cause first, pause the APIs & connections group from its tab; it comes back exactly as it was when you resume it. Every switch is a runtime filter, so deactivating SlimPress puts WordPress back to its default behaviour on the next request. There is nothing in core settings to clean up.
The short version
- Logged-out REST access feeds contact forms, booking plugins, WooCommerce blocks, embeds and headless front ends.
- If usernames are the worry, close the REST user list and
?author=lookups instead. - If you block it, record the namespaces your visitors use, allowlist them and test while logged out.
- Every change can be undone from the Tools tab.
SlimPress is free on WordPress.org, with no pro tier and no telemetry. Support happens in the WordPress.org forums, in public.
Originally published on pluginlab.dev.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.