Skip to content

REST API: Allow-list ability schema response keywords#11997

Open
gziolo wants to merge 3 commits into
WordPress:trunkfrom
gziolo:abilities-rest-schema-keyword-allow-list
Open

REST API: Allow-list ability schema response keywords#11997
gziolo wants to merge 3 commits into
WordPress:trunkfrom
gziolo:abilities-rest-schema-keyword-allow-list

Conversation

@gziolo
Copy link
Copy Markdown
Member

@gziolo gziolo commented May 28, 2026

What?

This hardens the Ability REST API schema response preparation by switching from an internal-keyword deny-list to a schema-keyword allow-list.

Ability input and output schemas exposed through REST responses now keep only:

  • keywords returned by rest_get_allowed_schema_keywords();
  • a small local set of additional draft-04 schema keywords that clients may use for validation or schema traversal.

This continues to preserve nested schema structures while stripping WordPress-internal keys such as sanitize_callback, validate_callback, and arg_options, along with other unsupported schema keywords such as example, examples, context, and readonly.

Why?

The previous implementation stripped only known internal keywords. An allow-list is stricter and better aligned with the REST API schema surface: unknown or unsupported schema keywords are not exposed to REST clients by default.

The local additional keyword list intentionally preserves a few draft-04 keywords that are useful to stricter client-side validators. This aligns with the approach documented in WordPress/gutenberg#78783, which adds tests for the strict JSON Schema keyword surface supported by the client-side abilities validator.

At the moment, the Core and Gutenberg changes aim to mirror the same allowed schema-property surface: unknown schema keywords should be skipped or stripped rather than passed through. Based on review feedback, we can also move in the opposite direction by relaxing the client-side validator to ignore unknown schema properties instead of treating them as unsupported. In practice, the two possible endpoints are either a strict shared allow-list or a relaxed client that skips unknown properties.

Test Coverage

This PR now mirrors the WordPress-specific keyword cases covered in WordPress/gutenberg#78783 by documenting that unsupported schema keywords are stripped from both ability input_schema properties and top-level output_schema definitions:

  • sanitize_callback
  • validate_callback
  • arg_options
  • example
  • examples
  • context
  • readonly

It also verifies that valid draft-04 required arrays are preserved. Boolean required handling is intentionally left for a follow-up PR.

Related

Testing

  • php -l tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php
  • git diff --check -- tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php

Attempted after the latest test-only update, but the local Docker runner hung after creating the PHPUnit container:

  • npm run test:php -- --filter Tests_REST_API_WpRestAbilitiesV1ListController

Previously run on this branch before the latest test-only update:

  • php -l src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php
  • npm run typecheck:php -- src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php --no-progress

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@gziolo gziolo marked this pull request as ready for review May 28, 2026 11:39
@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props gziolo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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.

1 participant