Hello @webtemyk, thanks for the reply.
This may have been fixed a long time ago, but I only realized this problem recently because of one plugin in one of my installations that started using REST API to update results in the front end.
I’ve reset the plugin as you suggested, but it did not solve the problem.
Now you say, if it doesn’t help, it’s not your plugin. But as soon as I deactivate and remove Clearfy, unauthenticated users have open access to the REST API.
When Clearfy is on, the returned error message is:
{"code":"rest_login_required","message":"REST API restricted to authenticated users.","data":{"status":401}}
A search using String Locator on the whole WordPress directory for the code exhibited when unauthenticated visitor tries an endpoint could only be found on a Clearfy file:
/wp-content/plugins/clearfy/includes/classes/class.configurate-performance.php
On lines 356 and following:
<pre><code>/**
* Disables the WP REST API for visitors not logged into WordPress.
*/
public function removeRestApi()
{
/*
Disable REST API link in HTTP headers
Link: <https://example.com/wp-json/>; rel="https://api.w.org/"
*/
remove_action('template_redirect', 'rest_output_link_header', 11);
/*
Disable REST API links in HTML <head>
<link rel='https://api.w.org/' href='https://example.com/wp-json/' />
*/
remove_action('wp_head', 'rest_output_link_wp_head', 10);
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd');
/*
Disable REST API
*/
if( version_compare(get_bloginfo('version'), '4.7', '>=') ) {
add_filter('rest_authentication_errors', [$this, 'disableWpRestApi']);
} else {
// REST API 1.x
add_filter('json_enabled', '__return_false');
add_filter('json_jsonp_enabled', '__return_false');
// REST API 2.x
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');
}
}
public function disableWpRestApi($access)
{
if( !is_user_logged_in() ) {
$message = apply_filters('disable_wp_rest_api_error', __('REST API restricted to authenticated users.', 'clearfy'));
return new WP_Error('rest_login_required', $message, ['status' => rest_authorization_required_code()]);
}
return $access;
}
So I hope this helps you guys pinpoint the problem, which apparently was not completely resolved when the setting to disable the REST API was removed.
Thanks.
-
This reply was modified 3 years, 9 months ago by
CB.