Description
After activation, visitors who are not logged in get an error (HTTP 401) from every route of the WordPress REST API. Logged-in users keep full access.
On the settings page you choose, for visitors and for each user role, between full access and a list of allowed routes. A blocked request of a logged-in user gets HTTP 403.
An allowed route works as it does without this plugin: WordPress and other plugins still apply their own permission checks.
Switching from an earlier plugin
Quietlatch REST Access can take over from the Disable REST API plugin (GPL2+, by Dave McHale). The first time it runs, it copies the rules saved by that plugin, for visitors and for every role, into its own settings. The settings of that plugin are not changed.
To give the same answers as before, these things are the same as in that plugin: the point where the check runs (rest_authentication_errors, priority 20), the order in which the roles of a user are looked at, the error code rest_cannot_access, the status 401 or 403, and the removal of the links to the REST API from the page head, the HTTP header and the RSD file. Its two filters, dra_allow_rest_api and dra_error_message, are still read, only for compatibility. The code itself was written anew.
Differences
- The error message is “Only authenticated users can access the REST API.” without the letters “DRA: ” in front.
- Routes can appear after you saved the rules of a role, for example when you install a plugin. In the earlier plugin such routes were open, also to visitors. Copied rules keep that behavior, so nothing changes on the day you switch, and the settings page marks these routes as “not in the saved list”. You can choose to block them instead. On a new install with no earlier rules they are blocked.
- A list saved by a version of the earlier plugin before 1.6 is copied as “visitors may use these routes only”. Any other address gets 401.
- A batch request (
/batch/v1) carries other requests inside it. Quietlatch REST Access checks each of them with the same rules. The earlier plugin checked the batch route only, so a role that was allowed to use it could reach a blocked route through it. - While the earlier plugin is still active, Quietlatch REST Access does nothing and shows a notice.
Settings
Settings > Quietlatch REST Access:
- Roles: a table of all roles with their access now.
- Rules for a role: full access, or only the routes you check. Routes are grouped by namespace, with “Check all” and “Uncheck all”.
- Routes that are not in a saved list: block or allow.
- Links to the REST API: remove them from the page head, the HTTP header and the RSD file (on by default).
The settings page does not use the REST API, so you can always open it and change the rules.
Privacy
Quietlatch REST Access makes no requests to other sites, collects no data, sets no cookies and keeps no log. It adds one small script and one stylesheet, on its own settings page only.
How it was made and tested
The code was written with the help of an AI coding assistant. It was tested automatically on a local test install (WordPress 7.1.4, PHP 8.3, theme Twenty Twenty-Five).
In that test, 11 sets of rules were saved with version 1.8 of the earlier plugin (several of them through its own settings form). For each set, 196 answers were recorded: REST API requests sent as a visitor and as users with the roles subscriber, editor, author and administrator and with two roles at once, logged in by application password and by cookie with and without the REST nonce, plus the front page and the RSD file. Then the earlier plugin was deactivated, Quietlatch REST Access copied the rules, and the same requests were sent again. The HTTP status, the error code and data, and the response body were the same, apart from the differences listed above. For two requests whose body changes on every call (oEmbed, and creating a draft) the status and the success were compared, not the whole body.
It has not been tested on multisite, on PHP 7.4, or together with plugins that add other ways to log in to the REST API.
Installation
- Install and activate Quietlatch REST Access.
- If the earlier plugin is active, Quietlatch REST Access stays paused and shows a notice. Deactivate the earlier plugin, but do not delete it yet: deleting it removes its settings.
- Open Settings > Quietlatch REST Access and check the table of roles. It says when rules were copied.
- After that you can delete the earlier plugin.
FAQ
-
Does the block editor keep working?
-
The block editor uses the REST API as the logged-in user. Roles have full access until you choose routes for them (copied rules stay as they were), so nothing changes for the editor after activation. If you choose routes for a role that edits content, allow the routes the editor needs.
-
A form or a feature for visitors stopped working. Why?
-
Some plugins let visitors use the REST API, for example to send a form. Allow the routes of that plugin under “Rules for: Visitors”.
-
What happens to routes that are added later?
-
See “Routes that are not in a saved list” on the settings page. Saving the rules of a role puts every route that exists at that moment into its list.
-
Which filters can I use?
-
quietlatch_rest_access_skip: returntrueto skip every check for the current request.quietlatch_rest_access_allowed: the decision for one request, with the route and the roles of the user.quietlatch_rest_access_error_message: the message of the error.
The two filters of the earlier plugin (
dra_allow_rest_api,dra_error_message) are read first, only for compatibility, and their result is passed to the matching filter above. -
What is removed when I delete the plugin?
-
The plugin’s own settings. Settings of the earlier plugin are not touched.
Reviews
There are no reviews for this plugin.
Contributors & Developers
“Quietlatch REST Access” is open source software. The following people have contributed to this plugin.
ContributorsTranslate “Quietlatch REST Access” into your language.
Interested in development?
Browse the code, check out the SVN repository, or subscribe to the development log by RSS.
Changelog
0.1.0
- First public version.
