Skip to content

🐛 fix(routing): pages check their capability; public REST routes say so - #123

Merged
gfazioli merged 5 commits into
masterfrom
fix/route-page-capability
Oct 6, 2026
Merged

gfazioli merged 5 commits into
masterfrom
fix/route-page-capability

Conversation

@gfazioli

@gfazioli gfazioli commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Three fixes in src/Routing, for 2.1.2. A page or a route that declares nothing behaves as before, with one exception, listed below.

Route and pages/ pages check the capability they ask for

The pages of config/routes.php and of pages/ are written straight into $_registered_pages, with no menu entry, and WordPress lets any logged-in user open a page registered that way. The capability key the docs and the Routes boilerplate declare was never read, so a route declared manage_options opened for a subscriber.

  • Both providers now refuse the page to a user without the capability, the way wp-admin/includes/menu.php refuses a page: admin_page_access_denied, then WordPress's own 403. The check runs on load-{hook} at PHP_INT_MIN, before any load callback, and again when the page renders (Support\Traits\AuthorizesAdminPages).
  • A route reads its capability key. A pages/ class says it with an optional public capability() method. It is not declared on Page: a subclass may already have one with another signature, and a class in pages/ never had to extend Page.
  • The default is read. A capability that is not a string (an array, true, 1) raises a notice and asks for read, instead of being cast to Array or to a user level.
  • The exception: a user with no role on the site, or a network user who is not a member of that site, used to open these pages, because WordPress skips its own check for a registered page with no menu entry. They lack read, so they are now refused.

A REST route without a permission_callback says it is public

Route merged 'permission_callback' => '__return_true' into every route that did not set one, so a Route::post() with no options was a public write endpoint, and WordPress's own notice about the missing argument never fired.

  • The route stays public, as it was. _doing_it_wrong() names it at rest_api_init and says how to make the choice explicit.
  • A null callback counts as missing, as in core's isset().
  • During a REST request WordPress sends the notice as an X-WP-DoingItWrong header, as it does for its own notices.
  • WP Bones 3.0 will refuse such a route.

The same pages give WordPress their title

A page with no menu entry has no title for get_admin_page_title(), so admin-header.php passed null to strip_tags(): a deprecation in debug.log on every visit, on PHP 8.1 and later. The load callback now sets the $title global. The <title> is unchanged, because the framework's admin_title filter still sets it.

Tests

  • composer test: 200 tests and 521 assertions, against 175 and 472 on master. The 25 new tests are in AdminRouteProviderTest, PageProviderTest and RestRouteTest.
  • Live, in WPKirk-Developing on wpbones.test, with route-capability-live-smoke.sh:
    • Setup: a subscriber and an administrator, both logged in over HTTPS, against two routes, two pages/ classes and three REST routes. debug.log is read from its size at the start.
    • v2.1.1: 7 ✗ of 23.
      • A subscriber gets a 200 from the manage_options route by GET and by POST, and from the manage_options page.
      • The REST response carries no notice.
      • Seven deprecations land in the log.
    • This branch: 23 ✓.

Review

  • Copilot could not review: the account's quota is exhausted.

  • Codex (gpt-6-sol, high):

    • round 1, on the whole branch: no actionable regression;
    • round 2, on 51bac68: one P2. is_callable() is true through __call(), and for a capability() that needs arguments. Fixed in the last commit: the method must be declared, public and argument-free.
  • An independent review found the points fixed in 51bac68:

    • the optional capability();
    • non-string capabilities;
    • admin_page_access_denied;
    • the version in the REST notice;
    • the exception above, now written down.

    It also tried breaking the fix on a scratch copy, and the tests caught each break.

The pages of config/routes.php and of pages/ are written straight into
$_registered_pages, with no menu entry, and WordPress lets any logged-in
user open a page registered that way: a subscriber opened a route declared
manage_options. The capability key the docs describe was never read.

Both providers now refuse the page with a 403 to a user without the
capability, on load before any other load callback and again on render.
A route reads its capability key; a Page class says it with capability().
The default is read, so a page that declares nothing behaves as before.
… public

Route merged permission_callback => __return_true into every route that
did not set one, so a Route::post() with no options was a public write
endpoint and WordPress's own notice about the missing argument never fired.

The route stays public, as it was, and _doing_it_wrong() names it and says
how to make that choice explicit. WP Bones 3.0 will refuse such a route.
A page with no menu entry has no title for get_admin_page_title(), so
admin-header.php passed null to strip_tags(): a deprecation in debug.log on
every visit, on PHP 8.1 and later. The load callback now sets the title
global, as WordPress expects from a page it does not know.
@gfazioli
gfazioli requested a balanced review from Copilot October 6, 2026 12:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

- capability() is optional and not declared by Page: a subclass may already
  have one with another signature (a declaration fatal in every wp-admin
  request), and a class in pages/ never had to extend Page.
- A capability that is not a string (an array, true, 1) asks for read with a
  notice, instead of being cast to 'Array' or to a user level.
- admin_page_access_denied fires before the refusal, as in core: multisite
  hangs its splash on it.
- The REST notice carries no version: WordPress prints it as its own.
is_callable() is true through __call() as well, and for a method that needs
arguments (Codex, round 2 on #123). The method must be declared, public and
callable with no arguments; otherwise the page asks for read.
@gfazioli
gfazioli merged commit 8c159f9 into master Oct 6, 2026
4 checks passed
@gfazioli
gfazioli deleted the fix/route-page-capability branch October 6, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants