The WordPress REST API is accessible to everyone by default, even without logging in. This makes it possible for attackers to retrieve usernames, posts, and site structure, or to carry out brute-force attacks. By disabling the API, restricting it to logged-in users, or securing it with authentication and rate limiting, you significantly reduce this risk without losing functionality.
Why REST API security is necessary
By default, WordPress gives every visitor access to endpoints such as /wp-json/wp/v2/users, which exposes usernames. This is useful information for brute-force attacks on your login page. Malicious scripts may also attempt to modify data via endpoints that are insufficiently protected. An unsecured API is therefore not a direct leak, but it is a stepping stone to further attacks.
/wp-json/ after your domain name. This lets you see immediately what is visible to everyone.Disabling or restricting the REST API
Not every website needs the REST API for external integrations or mobile apps. If you don’t use any apps or headless functionality, you can restrict the API to logged-in users. Add this to the functions.php file of your (child) theme:
add_filter('rest_authentication_errors', function($result) {
if (!is_user_logged_in()) {
return new WP_Error('rest_not_logged_in', 'REST API only for logged-in users', array('status' => 401));
}
return $result;
});
Note: this will also block functionality that uses the REST API for non-logged-in visitors, such as certain search functions, contact forms, or blocks in the Gutenberg editor. Always test this on a staging environment first before putting it live.
Check dependencies
Determine which plugins or themes use the REST API. Open the browser console on your site and check for error messages after applying the restriction.
Restrict or filter endpoints
Choose to fully restrict access to logged-in users, or filter specific endpoints such as /wp/v2/users with a targeted rest_endpoints filter.
Test thoroughly
Navigate to /wp-json/ and check that sensitive data is no longer visible, and test whether your site and plugins continue to function normally.
Authentication and authorization
If you do need the REST API for an app, integration, or external system, ensure proper authentication rather than leaving everything open.
Application Passwords: since WordPress 5.6, you can create application passwords in the user profile. This is the built-in, secure way to grant external applications access without sharing your main password, and it is revocable per application.
JWT authentication: for more control over tokens and expiration times, you can install a JWT plugin. This requires a bit more configuration but gives granular control over which application has which permissions.
API keys per integration: give each external party its own key or credential. This way, if there is a breach, you can revoke one connection without taking down the entire API.
Additional security measures
In addition to authentication, there are supplementary measures that further reduce your vulnerability:
Rate limiting: limit the number of requests per IP address per time unit to prevent brute-force attempts. Many LiteSpeed server environments offer this at the server level, in addition to anything you configure in a security plugin.
CORS headers: specify which domains are allowed to call your API, so other websites cannot misuse your endpoints unnoticed.
Monitoring: install a security plugin that logs and blocks suspicious REST API requests, so you can quickly see if misuse is occurring.
Server and email security: security doesn’t stop at the API alone. Also make sure your business email is properly configured and that your hosting stays up-to-date; in Plesk, for example, you can easily see which PHP version and modules are active.
Frequently asked questions
Can I disable the REST API entirely without issues?
Yes, you can, but first check whether plugins, themes, or the block editor depend on it. Always test changes on a staging environment before going live.
Is the REST API needed for the WordPress dashboard?
Yes, the dashboard uses the REST API, among other things, for the block editor. Make sure logged-in users always retain access and only block non-logged-in requests.
How do I notice misuse of my REST API?
A security plugin that logs requests provides insight into unusual patterns, such as many requests from a single IP address in a short period.
Does this also work if I switch to a different hosting provider?
Yes, these adjustments are independent of your hosting provider and work on any server with PHP and Plesk. Check out the steps for switching to Tandata if you want to handle this all at once.
Conclusion
An unsecured REST API gives attackers useful information and attack opportunities. Restrict the API to logged-in users if you don’t use external integrations, and for integrations you do need, use application passwords or JWT authentication, supplemented with rate limiting and monitoring. You can find more background articles about website security in our knowledge base.