From dbccd5fb0741ab1385678d0efaa7ed607afc388d Mon Sep 17 00:00:00 2001 From: Javier Casares Date: Fri, 7 Aug 2026 11:57:51 +0000 Subject: [PATCH 01/11] v3.1.1 --- changelog.txt | 17 ++++++++++ noindex-seo.php | 88 ++++++++++++++++++++++++++++++++++++++++++++++--- readme.txt | 21 ++++++++++-- 3 files changed, 120 insertions(+), 6 deletions(-) diff --git a/changelog.txt b/changelog.txt index 73baf19..3e1fbc9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 `` 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. diff --git a/noindex-seo.php b/noindex-seo.php index 397cbf7..a84a9c9 100644 --- a/noindex-seo.php +++ b/noindex-seo.php @@ -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 `` 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. * diff --git a/readme.txt b/readme.txt index 7209339..456d7d2 100644 --- a/readme.txt +++ b/readme.txt @@ -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 `` 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. From ce09aa77e5960d17c9ddf96601e57aff23953369 Mon Sep 17 00:00:00 2001 From: Javier Casares Date: Mon, 10 Aug 2026 19:07:06 +0000 Subject: [PATCH 02/11] v3.1.2 --- README.md | 36 ++++++++++++++++++++++ changelog.txt | 38 +++++++++++++++++++++++ noindex-seo.php | 80 +++++++++++++++++++++++++++++++++---------------- readme.txt | 42 ++++++++++++++++++++++++-- 4 files changed, 168 insertions(+), 28 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..a11a859 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# noindex SEO + +Control search engine indexing with robots directives (`noindex`, `nofollow`, `noarchive`, `nosnippet`, `noimageindex`) for specific parts of your WordPress site. + +## For end users + +See [`readme.txt`](readme.txt) for installation, usage, and the WordPress.org-format changelog. + +## For developers / contributors + +- **[`CLAUDE.md`](CLAUDE.md)** — project-specific architecture, data model, tooling setup, and deliberate exceptions to the AGENTS defaults. Read this first. +- **[`AGENTS.md`](AGENTS.md)** — index to the contribution guidelines (security, compatibility, tooling, testing, deployment). Topic-specific rules live in the `AGENTS-*.md` files. + +## Common commands + +```bash +composer install # Install dev dependencies +vendor/bin/phpcs # WordPress Coding Standards +vendor/bin/phpstan analyse --memory-limit=1G # Static analysis (level 9) +vendor/bin/phpunit # Test suite (71 tests) +bash bin/preflight.sh # Full pre-deploy verification +``` + +## Test setup + +Copy the sample config and fill in your local DB credentials: + +```bash +cp tests/wp-tests-config.sample.php tests/wp-tests-config.php +``` + +The WordPress test library must be installed at `/tmp/wordpress-tests-lib` (or set `WP_TESTS_DIR`). + +## License + +GPL-3.0-or-later. See [LICENSE](LICENSE). diff --git a/changelog.txt b/changelog.txt index 3e1fbc9..d33c463 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,43 @@ == Changelog == += 3.1.2 [2026-08-10] = + +Audit-driven maintenance release. + +**Security** + +* Fixed the composer-audit gate in `bin/preflight.sh`. The previous version grepped for "security vulnerability advisory" (singular), which never matched Composer's actual output "security vulnerability advisories" (plural) — the y→i pluralization change silently disabled CVE detection, green-lighting every release regardless of known vulnerabilities. The gate now uses Composer's bitmask exit code (bit 0 = security), which is immune to wording changes. +* Bumped `squizlabs/php_codesniffer` to ^3.13.6 and `wp-coding-standards/wpcs` to ^3.4.1, fixing CVE-2026-67434 (OS command injection) and CVE-2026-45293 (arbitrary code execution) in the development tooling. These are dev-only dependencies and were never shipped in the release ZIP. + +**Fixed** + +* Nested `
` elements on the settings page. The "Apply Recommended Defaults" form was physically nested inside the main settings form — HTML5 forbids this, and the stray `
` could close the main form early, orphaning the "Save Changes" button and all directive checkboxes. The apply-suggestions form is now a standalone sibling rendered before the main form. +* Meta-box "Effective Directives" reference panel now reads from the consolidated `noindex_seo_settings` option via `noindex_seo_get_setting()` instead of the stale legacy individual options that may diverge after a settings save. + +**Added** + +* `load_plugin_textdomain('noindex-seo')` hooked on `init`. The plugin ships `.mo` files for Catalan and Spanish (es_ES) in `languages/`, but without this call WordPress only loaded translations from `wp-content/languages/plugins/` — the bundled translations were effectively dead code. +* PHPUnit coverage measurement in `bin/preflight.sh` (requires Xdebug). Enforces a 25% regression floor against the current 26.64% baseline; the AGENTS target remains 80%. +* `` configuration in `phpunit.xml` so `--coverage-text` produces a report. +* `README.md` for developer and contributor onboarding. +* `tests/wp-tests-config.sample.php` template. The real `tests/wp-tests-config.php` is now gitignored and reads from environment variables. + +**Changed** + +* Pinned all remaining wildcard `"*"` dev dependencies to caret constraints in `composer.json` (`phpcsutils` ^1.2, `php-compatibility` ^9.3, `dealerdirect/phpcodesniffer-composer-installer` ^1.2). Unpinned ranges were how the CVE-affected versions were resolved. +* Lowered `phpstan.neon` `phpVersion` from 80500 (PHP 8.5) to 80200 (PHP 8.2) so PHPStan flags any accidental use of PHP 8.3+ syntax that would break on the development floor. +* Refreshed `CLAUDE.md` to reflect 3.1.x reality (version, line count, v3 consolidated storage model, four-priority output logic, current 8-file test suite). Documented the uninstall direct-DB exception. +* Updated `TODO.md` to mark shipped items (#1–#4). + +**Compatibility** + +* WordPress: 5.7 - 7.1 +* PHP: 7.2 - 8.5 + +**Tests** + +* 71 tests, 385 assertions — all passing. Coverage measured at 26.64% (471/1768 lines). + = 3.1.1 [2026-07-18] = **Security** diff --git a/noindex-seo.php b/noindex-seo.php index a84a9c9..8da13de 100644 --- a/noindex-seo.php +++ b/noindex-seo.php @@ -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.1 + * Version: 3.1.2 * Author: ROBOTSTXT * Author URI: https://www.robotstxt.es/ * License: GPL-3.0-or-later @@ -51,8 +51,13 @@ defined( 'ABSPATH' ) || die( 'Bye bye!' ); * 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. + * @since 3.1.2 Audit-driven maintenance release: fixed broken CVE gate in + * bin/preflight.sh, un-nested the settings page forms (HTML5 + * compliance), added load_plugin_textdomain() for bundled + * translations, pinned all dev dependencies, wired up coverage + * measurement, refreshed project docs. */ -define( 'NOINDEX_SEO_VERSION', '3.1.1' ); +define( 'NOINDEX_SEO_VERSION', '3.1.2' ); /** * Option key holding the consolidated plugin settings array. @@ -746,6 +751,27 @@ add_action( 'admin_init', 'noindex_seo_register' ); add_action( 'admin_menu', 'noindex_seo_menu' ); add_action( 'admin_enqueue_scripts', 'noindex_seo_enqueue_admin_assets' ); add_action( 'plugins_loaded', 'noindex_seo_check_migration' ); +add_action( 'init', 'noindex_seo_load_textdomain' ); + +/** + * Loads the plugin's translated strings from the bundled languages directory. + * + * WordPress auto-loads translations from `wp-content/languages/plugins/`, but + * the `.mo` files shipped in the plugin's own `languages/` directory require + * this explicit call. Hooked on {@see 'init'} so the text domain is available + * before any user-facing string is rendered. + * + * @since 3.1.2 + * + * @return void + */ +function noindex_seo_load_textdomain(): void { + load_plugin_textdomain( + 'noindex-seo', + false, + dirname( plugin_basename( __FILE__ ) ) . '/languages' + ); +} /** * Excludes noindexed posts from the core XML sitemap (WP 5.5+). @@ -1874,8 +1900,7 @@ function noindex_seo_render_meta_box( WP_Post $post ): void { $context = ( 'page' === $post_type ) ? 'page' : 'single'; foreach ( $directives as $directive ) { - $option_key = $directive . '_seo_' . $context; - if ( get_option( $option_key, 0 ) ) { + if ( noindex_seo_get_setting( $context, $directive ) ) { $global_directives[] = $directive; } } @@ -3216,6 +3241,31 @@ function noindex_seo_admin(): void { } ?> + +
+ + + __( 'Enable all directives for the 12 contexts flagged as recommended.', 'noindex-seo' ), + ) + ); + ?> + + + +
+ +
@@ -3354,28 +3404,6 @@ function noindex_seo_admin(): void {

- - - - - __( 'Enable all directives for the 12 contexts flagged as recommended.', 'noindex-seo' ), - ) - ); - ?> - - - -
-