This commit is contained in:
Javier Casares 2026-08-07 11:57:51 +00:00
commit dbccd5fb07
3 changed files with 120 additions and 6 deletions

View file

@ -1,5 +1,22 @@
== Changelog ==
= 3.1.1 [2026-07-18] =
**Security**
* Tightened the ACL on the two REST endpoints introduced in 3.1.0. The original release used `__return_true` for both `permission_callback`s, which would have leaked the full noindex configuration to anyone hitting `/wp-json/noindex-seo/v1/settings`. Fixed callbacks:
- `/settings` now requires `manage_options`. The consolidated array reveals the site's full SEO strategy in a single response, so it is admin-only.
- `/effective?post_id=N` is public only for posts with `post_status=publish` and no password (the directives for those would appear in the HTML `<meta>` tag of the rendered page anyway). Drafts, private posts, scheduled posts, password-protected posts, and trashed posts require `edit_post` capability for the specific post.
**Compatibility**
* WordPress: 5.7 - 7.1
* PHP: 7.2 - 8.5
**Tests**
* Added 4 tests covering the new permission model: unauthenticated rejected on `/settings`, editor rejected on `/settings`, unauthenticated/subscriber rejected on `/effective` for drafts, public access preserved on `/effective` for published posts.
= 3.1.0 [2026-07-18] =
Closes the three remaining HIGH-priority items from the original gap audit.

View file

@ -5,7 +5,7 @@
* Description: Control search engine indexing with robots directives (noindex, nofollow, noarchive, nosnippet, noimageindex) for specific parts of your WordPress site.
* Requires at least: 5.7
* Requires PHP: 7.2
* Version: 3.1.0
* Version: 3.1.1
* Author: ROBOTSTXT
* Author URI: https://www.robotstxt.es/
* License: GPL-3.0-or-later
@ -46,8 +46,13 @@ defined( 'ABSPATH' ) || die( 'Bye bye!' );
* gets its own directive settings; (3) REST API exposure —
* /wp-json/noindex-seo/v1/{settings,effective} so headless
* consumers can read the configuration.
* @since 3.1.1 Security hardening on the REST endpoints: /settings now
* requires `manage_options`; /effective is public only for
* published + non-password-protected posts and requires
* `edit_post` for everything else. The previous `__return_true`
* callback would have leaked the full configuration to anyone.
*/
define( 'NOINDEX_SEO_VERSION', '3.1.0' );
define( 'NOINDEX_SEO_VERSION', '3.1.1' );
/**
* Option key holding the consolidated plugin settings array.
@ -944,7 +949,7 @@ function noindex_seo_register_rest_routes(): void {
array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'noindex_seo_rest_get_settings',
'permission_callback' => '__return_true',
'permission_callback' => 'noindex_seo_rest_settings_permission_check',
),
)
);
@ -956,7 +961,7 @@ function noindex_seo_register_rest_routes(): void {
array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'noindex_seo_rest_get_effective',
'permission_callback' => '__return_true',
'permission_callback' => 'noindex_seo_rest_effective_permission_check',
'args' => array(
'post_id' => array(
'type' => 'integer',
@ -971,6 +976,81 @@ function noindex_seo_register_rest_routes(): void {
}
add_action( 'rest_api_init', 'noindex_seo_register_rest_routes' );
/**
* Permission callback for the /settings endpoint.
*
* The consolidated settings array reveals the site's full SEO strategy in a
* single response (every context × directive combination plus internal
* flags like delete_on_uninstall). That is admin-only information; an
* unauthenticated caller could otherwise enumerate the entire noindex
* configuration by hitting the endpoint once. Restrict to `manage_options`.
*
* @since 3.1.1
*
* @return true|WP_Error True if the current user can manage options, WP_Error otherwise.
*/
function noindex_seo_rest_settings_permission_check() {
if ( ! current_user_can( 'manage_options' ) ) {
return new WP_Error(
'noindex_seo_rest_forbidden',
__( 'You do not have permission to read the noindex SEO settings.', 'noindex-seo' ),
array( 'status' => rest_authorization_required_code() )
);
}
return true;
}
/**
* Permission callback for the /effective endpoint.
*
* The effective directives for a post are the same information that would
* appear in the HTML `<meta name="robots">` tag (or `X-Robots-Tag` header)
* when the post is rendered on the front-end. They are therefore public for
* posts that are themselves publicly viewable:
*
* - `publish` status AND no password → public access (no auth required).
*
* For everything else (drafts, private posts, future/scheduled posts,
* password-protected posts, trashed posts), the directives are admin-only
* and the caller must have the `edit_post` capability for that post.
*
* If the requested post does not exist, permission is granted so that the
* callback can return a proper 404 instead of a 401 (this matches the
* behaviour of WP core's posts controller).
*
* @since 3.1.1
*
* @param WP_REST_Request $request The current request, with `post_id`.
* @return true|WP_Error True if access is allowed, WP_Error otherwise.
*/
function noindex_seo_rest_effective_permission_check( WP_REST_Request $request ) {
$raw_post_id = $request->get_param( 'post_id' );
$post_id = is_numeric( $raw_post_id ) ? (int) $raw_post_id : 0;
$post = get_post( $post_id );
// Missing post: defer to the callback, which returns a 404.
if ( ! $post ) {
return true;
}
// Public post (published + not password-protected): directives are
// equivalent to what would appear in the rendered HTML.
if ( 'publish' === $post->post_status && empty( $post->post_password ) ) {
return true;
}
// Everything else requires edit permission for the specific post.
if ( ! current_user_can( 'edit_post', $post->ID ) ) {
return new WP_Error(
'noindex_seo_rest_forbidden',
__( 'You do not have permission to read directives for this post.', 'noindex-seo' ),
array( 'status' => rest_authorization_required_code() )
);
}
return true;
}
/**
* REST callback: returns the consolidated settings array.
*

View file

@ -3,9 +3,9 @@ Contributors: javiercasares
Tags: seo, noindex, nofollow, noarchive, robots
Requires at least: 5.7
Tested up to: 7.1
Stable tag: 3.1.0
Stable tag: 3.1.1
Requires PHP: 7.2
Version: 3.1.0
Version: 3.1.1
License: GPL-3.0-or-later
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
@ -114,6 +114,23 @@ Extract the contents of the ZIP and upload the contents to the `/wp-content/plug
== Changelog ==
= 3.1.1 [2026-07-18] =
**Security**
* Tightened the ACL on the two REST endpoints introduced in 3.1.0. The original release used `__return_true` for both `permission_callback`s, which would have leaked the full noindex configuration to anyone hitting `/wp-json/noindex-seo/v1/settings`. Fixed callbacks:
- `/settings` now requires `manage_options`. The consolidated array reveals the site's full SEO strategy in a single response, so it is admin-only.
- `/effective?post_id=N` is public only for posts with `post_status=publish` and no password (the directives for those would appear in the HTML `<meta>` tag of the rendered page anyway). Drafts, private posts, scheduled posts, password-protected posts, and trashed posts require `edit_post` capability for the specific post.
**Compatibility**
* WordPress: 5.7 - 7.1
* PHP: 7.2 - 8.5
**Tests**
* Added 4 tests covering the new permission model: unauthenticated rejected on `/settings`, editor rejected on `/settings`, unauthenticated/subscriber rejected on `/effective` for drafts, public access preserved on `/effective` for published posts.
= 3.1.0 [2026-07-18] =
Closes the three remaining HIGH-priority items from the original gap audit.