From 401e90b913b2c3cd093e253299385a541fb1c653 Mon Sep 17 00:00:00 2001 From: Pollora maintainer Date: Thu, 3 Dec 2026 15:20:24 +0100 Subject: [PATCH] fix(guidelines): say how an AJAX action without a nonce choice behaves --- CHANGELOG.md | 6 ++++++ resources/boost/guidelines/core.blade.php | 2 +- resources/boost/skills/pollora-rest-api/SKILL.md | 2 +- tests/Feature/Guidelines/CoreGuidelinesTest.php | 6 ++++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0357872..ce6ef27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.9.3] - 2026-12-03 + +### Fixed + +- The core guidelines and the REST and AJAX skill no longer announce a future major version of `pollora/ajax`: 2.0 is out. They say that an action which chose no nonce runs unchecked in a Pollora project unless `pollora.ajax.nonce_by_default` is `true`. + ## [1.9.2] - 2026-11-27 ### Changed diff --git a/resources/boost/guidelines/core.blade.php b/resources/boost/guidelines/core.blade.php index 1b7f79f..e202f05 100644 --- a/resources/boost/guidelines/core.blade.php +++ b/resources/boost/guidelines/core.blade.php @@ -137,7 +137,7 @@ class InternalHelper {} - **Which template answered?** With `WP_DEBUG` on, every page carries `` (hierarchy responses only, not `Route::wp()` or Laravel routes) - **Debugging**: `composer require --dev pollora/debugbar` adds Pollora's and WordPress's tabs to Laravel Debugbar — what answered the request (route, or hierarchy view and condition), `$wpdb` queries, hooks, WordPress phases, and REST/admin-ajax calls in the bar's request list. Prefer it to Query Monitor. Plugins add data with the `pollora/debugbar/register` action (no dependency), packages by extending `Pollora\Debugbar\Collector`; `wp_*` and `pollora*` tab names are reserved - **Meta, roles, bindings**: declare a meta with `#[Meta]` on a typed property rather than calling `register_meta()` and casting `get_post_meta()` by hand (`pollora-typed-meta` skill); declare roles with `#[Role]` / `#[ModifyRole]` rather than `add_role()`, and check a capability (`can:`, `@can`) rather than a role (`pollora-roles` skill); bind core blocks to a `#[BlockBinding]` source or `pollora/post-meta` before writing a custom block (`pollora-block-bindings` skill) -- **CSRF and nonces**: WordPress endpoints are excluded from Laravel CSRF — WordPress uses its own nonce system. Say how every `#[Ajax]` action is protected (pollora/ajax 1.2+): `nonce: true` verifies a nonce (create it with `wp_create_nonce('action')`, send it as `_ajax_nonce`) before the method runs, `nonce: false` turns it off on purpose; an action that does not say still runs unchecked for now and is reported with `WP_DEBUG`, and the next major version of `pollora/ajax` verifies a nonce by default. Never leave an action open to guests without deciding. A REST route is protected by its permission callback +- **CSRF and nonces**: WordPress endpoints are excluded from Laravel CSRF — WordPress uses its own nonce system. Say how every `#[Ajax]` action is protected (pollora/ajax 1.2+): `nonce: true` verifies a nonce (create it with `wp_create_nonce('action')`, send it as `_ajax_nonce`) before the method runs, `nonce: false` turns it off on purpose; an action that does not say runs unchecked in a Pollora project, and is reported with `WP_DEBUG`, unless `pollora.ajax.nonce_by_default` is `true` (`config/pollora/ajax.php`, set by the skeleton from 13.45.0), which verifies it like `nonce: true`. Never leave an action open to guests without deciding. A REST route is protected by its permission callback - **Modules**: Use `nwidart/laravel-modules` for large projects — `pollora:make:module` creates a lean module (no provider: discovery works inside modules), built with `@pollora/vite-config`; switch modules with `module:enable|disable` or Plugins › Modules (see the `pollora-modules` skill) ### Available Artisan Commands diff --git a/resources/boost/skills/pollora-rest-api/SKILL.md b/resources/boost/skills/pollora-rest-api/SKILL.md index 8d58a38..1eb2925 100644 --- a/resources/boost/skills/pollora-rest-api/SKILL.md +++ b/resources/boost/skills/pollora-rest-api/SKILL.md @@ -195,7 +195,7 @@ The `nonce` parameter: | `true` | Verifies a nonce named after the action before the method runs. A request without a valid one gets a 403 (`pollora_ajax_invalid_nonce`) and the method does not run | | `'notes_form'` | Verifies the nonce of that name | | `false` | No nonce, on purpose (a public beacon, a webhook that signs its own requests) | -| not given | Not chosen yet: the action runs **without a check** and WordPress is told (`_doing_it_wrong()`, visible with `WP_DEBUG`). The next major version of `pollora/ajax` verifies a nonce by default | +| not given | Depends on the project: verified like `true` when `pollora.ajax.nonce_by_default` is `true` (`config/pollora/ajax.php`, set by the skeleton from 13.45.0). Otherwise the action runs **without a check** and WordPress is told (`_doing_it_wrong()`, visible with `WP_DEBUG`) | The page creates the nonce for the same name, `wp_create_nonce('subscribe')`, and sends it in the `_ajax_nonce` field. Always choose `true` or `false` when you write an action: never leave it out, and never write `nonce: false` for an action that changes data without another protection. A guest's nonce is tied to no user and a cached page can serve an old one, so prefer another protection for an action open to guests. A `check_ajax_referer()` call in a method that declares `nonce: true` is redundant; a method that verifies the nonce by hand says `nonce: false`, so that Pollora does not report it. diff --git a/tests/Feature/Guidelines/CoreGuidelinesTest.php b/tests/Feature/Guidelines/CoreGuidelinesTest.php index 614f233..8c187ea 100644 --- a/tests/Feature/Guidelines/CoreGuidelinesTest.php +++ b/tests/Feature/Guidelines/CoreGuidelinesTest.php @@ -60,7 +60,8 @@ public function render(string $path): string ->toContain('Say how every `#[Ajax]` action is protected (pollora/ajax 1.2+)') ->toContain('`nonce: true` verifies a nonce') ->toContain('`nonce: false` turns it off on purpose') - ->toContain('the next major version of `pollora/ajax` verifies a nonce by default') + ->toContain('unless `pollora.ajax.nonce_by_default` is `true`') + ->not->toContain('next major version of `pollora/ajax`') ->toContain('Never leave an action open to guests without deciding'); }); @@ -73,7 +74,8 @@ public function render(string $path): string ->toContain('pollora_ajax_invalid_nonce') ->toContain('wp_create_nonce(\'subscribe\')') ->toContain('->requireNonce()') - ->toContain('The next major version of `pollora/ajax` verifies a nonce by default') + ->toContain('verified like `true` when `pollora.ajax.nonce_by_default` is `true`') + ->not->toContain('next major version of `pollora/ajax`') ->not->toContain("check_ajax_referer('newsletter')"); });