Skip to content

wp-build page template renders generated admin pages without any capability check, exposing them to logged-out visitors #82251

Closed

Description

@shameemreza

Description

The page template in packages/wp-build/templates/page.php.template hooks an interceptor to admin_init that renders the full generated page whenever $_GET['page'] matches the page slug, then exits (lines 329 to 341 on trunk):

​ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_intercept_render() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['page'] ) && '{{PAGE_SLUG}}' === $_GET['page'] ) { {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page(); exit; } } add_action( 'admin_init', '{{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_intercept_render' ); ​

There is no capability check, and the template has no capability placeholder at all. Since wp-admin/admin-post.php fires admin_init for logged-out requests (to support admin_post_nopriv_ actions), every page generated from this template is served to anonymous visitors.

Suggested fix

Add a capability to the page build config, emit it into the template, and guard the interceptor with is_user_logged_in() and current_user_can() before rendering. Limiting the interceptor to the intended admin screen instead of every admin_init would also keep it off admin-post.php entirely. I am happy to work on a PR for this.

Step-by-step reproduction instructions

  1. Clean WordPress trunk install, no plugins.
  2. Log out, or use a session with no cookies.
  3. Request /wp-admin/admin-post.php?page=font-library.

Result: HTTP 200 with the full font library app shell, block editor scripts, module preloads for the font-list and fonts-home routes, and REST preload data. A PHP deprecation notice from wp-admin/includes/plugin.php also leaks into the page title. The same applies to page=options-connectors and any other page generated from this template. In core, the Fonts menu entry is registered with the edit_theme_options capability, so the interceptor bypasses the gate the menu enforces.

Reported against core as https://core.trac.wordpress.org/ticket/66001. The affected files in core are build artifacts generated from this template, so the fix belongs here.

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress: 7.2-alpha-63166-src (wordpress-develop trunk, local Docker environment)
  • PHP: 8.3.33
  • Browser: n/a, reproducible with curl
  • Plugins: none

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. added
    [Type] Bug
    on Aug 31, 2026
  2. added
    [Status] In Progress
    on Aug 31, 2026
  3. moved this from 🏗️ In Progress to 🐛 Punted to 7.1.1 in WordPress 7.1 Editor Taskson Aug 31, 2026
  4. annezazu commented on Aug 31, 2026

    @annezazu
    Contributor

    @draganescu / @aaronjorbin this would be a good candidate for a 7.1.x release. Added it to the project board for consideration.

  5. youknowriad commented on Aug 31, 2026

    @youknowriad
    Contributor

    Agreed that a capability check seems to be a good addition here. The REST APIs used by these pages are already controlled properly and the menu items linking to these pages as well but a capability check to improve the UX would be better indeed.

  6. courtneyr-dev commented on Aug 31, 2026

    @courtneyr-dev
    Contributor

    Adding a capability-check control test, since the thread is weighing exposure vs. a hardening gap. I split it into two questions — is the interceptor reachable without the capability, and does anything private actually cross the boundary — and ran both against WordPress 7.1 (the GA release), on single-site and multisite (wp-includes/build/pages/font-library/page.php, the generated artifact of this template).

    Reachability (shipped-source). In 7.1 admin-post.php calls do_action( 'admin_init' ) at line 27, before its is_user_logged_in() check at line 36. The interceptor is hooked to admin_init and exits inside the render, so it runs and returns before auth is ever evaluated. Confirmed — matches the report.

    What actually crosses the boundary. wp_font_library_render_page() has no current_user_can() anywhere, but the only server-side data it emits is from wp_font_library_preload_data(), which preloads exactly two paths:

    '/?_fields=…'                          // the REST index — public
    array( '/wp/v2/settings', 'OPTIONS' )  // schema, not values

    rest_preload_api_request() dispatches each in the current user's context. I dispatched both as logged-out, as an authenticated Subscriber (no edit_theme_options), and as an admin:

    context edit_theme_options index / preload GET /wp/v2/settings
    logged-out no public fields only 401
    Subscriber no public fields only 403
    admin (control) yes public fields only 200

    Same numbers on single-site and multisite. The index preload returns only the fields WP_REST_Server::get_index() adds unconditionally — name, description, url, home, gmt_offset, timezone_string, page_on_front, etc. — which is exactly what any anonymous client already reads from /wp-json/. The fields core gates behind current_user_can( 'upload_files' ) (image_sizes, image_size_threshold, image_strip_meta, image_max_bit_depth) showed up for the admin on the multisite run and never for anon or the Subscriber — the boundary holds field by field. The admin's 200 on the direct settings GET is the positive control: the probe can see private values when they're exposed, and they never appear in the anonymous render. admin_email and every other gated setting stay behind their permission callback.

    So @youknowriad's read holds up under test — the REST layer enforces capabilities correctly and independently of this page. The Subscriber row is the piece the logged-out repro doesn't cover: it isolates the capability boundary from the auth boundary and shows the gap is specifically a missing check on the renderer, not anything the data layer gets wrong.

    What the gap is, then. An unauthenticated request reaches an admin-screen renderer that runs set_current_screen(), dispatches two REST requests, and fires font-library_init, admin_head, and admin_footer — hooks an extension author can reasonably assume only fire for an authorized admin. No core data leaks; the residual risk is whatever an extension does on those hooks pre-auth. That's a real reason to add the guard, as hardening rather than disclosure.

    Same in options-connectors, and not new in 7.1. The other generated page preloads the identical two paths, so it's no worse. The interceptor and the absent check are the same in the 7.0.4 build too (0 current_user_can/is_user_logged_in in that page.php; only the preloaded _fields list differs), so this has shipped for at least two releases — relevant to the 7.1.x backport question.

    Suggested guard matches what's already proposed: gate the interceptor with is_user_logged_in() + current_user_can( <the page's cap> ), or only hang it on the intended admin screen so it never runs on admin_init for admin-post.php. Emitting a capability into the page config (there's no placeholder today) is the template change that needs to happen.

    Environment: WordPress 7.1 (GA), single-site and multisite, SQLite, PHP 8.5, no plugins. Same result on both. Happy to share the control-test script and raw output.

    Use of AI Tools

    AI assistance: Yes
    Tool(s): Claude Code
    Used for: drafting the reproduction and the capability-check control test, running the three-context control matrix against local WordPress 7.1 GA builds (single-site and multisite), and reading the generated page.php and WP_REST_Server::get_index() in core source. I reviewed the analysis, re-ran the control test, and take responsibility for the finding and its severity assessment.

  7. shameemreza commented on Sep 1, 2026

    @shameemreza
    ContributorAuthor

    Thanks @courtneyr-dev for the detailed test matrix. The Subscriber row separating the capability boundary from the auth boundary is a distinction the original report didn't make, and confirming that nothing capability-gated crosses the REST layer settles the disclosure question. The hardening framing matches what surfaced during the fix too.

    The template change you explained is implemented in #82254: the interceptor now calls auth_redirect() for logged-out visitors and current_user_can() with a per-page capability before rendering, and the page config gained a capability field. It defaults to manage_options, font-library declares edit_theme_options, and the other generated pages are matched to the capabilities their menu registrations use. I ran the three contexts from your table against wp-env with the patched build: anonymous gets a 302 to the login screen, a Subscriber gets a 403, and an admin renders normally.

    The PR is approved and waiting on a committer. If you want to run your matrix against that branch, that would be a useful extra data point, especially for the 7.1.x backport consideration @annezazu raised: #82254

  8. moved this from 🐛 Punted to 7.1.1 to ✅ Done in WordPress 7.1 Editor Taskson Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

[Status] In Progress[Type] Bug

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions