-
Notifications
You must be signed in to change notification settings - Fork 3.2k
REST API: Implement strict validation for the settings controller. Fi… #10662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
REST API: Implement strict validation for the settings controller. Fi… #10662
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
westonruter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the formatting issues.
src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
Outdated
Show resolved
Hide resolved
src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
Outdated
Show resolved
Hide resolved
Correct inner comment to use normal multi-line comment, align closing tags, and remove trailing whitespace.
Description
This PR addresses the issue where the /wp/v2/settings endpoint returns a 200 OK even when sent unknown properties or an empty request body.
Changes:
Updated WP_REST_Settings_Controller::update_item to validate request parameters against registered settings.
Introduced a whitelist for "Infrastructure/Global" parameters (e.g., _locale, _wpnonce, _fields, _embed) to ensure backward compatibility and prevent breaking internal WordPress tools.
Returns a rest_invalid_param (400) if unknown parameters are passed in the JSON body or URL query string.
Returns a rest_empty_request (400) if the request does not contain any valid settings to update.
Why this approach works: Previous attempts were reverted because they broke requests using query parameters or global flags. By using an array_diff against a whitelist of registered options AND internal parameters, this patch provides strict validation without breaking existing ecosystem tools like Gutenberg or third-party clients.
Testing performed:
Added unit tests for empty bodies.
Added unit tests for unknown properties in JSON bodies and URL query strings.
Verified that global parameters (like _locale) still allow the request to succeed.
Trac ticket: https://core.trac.wordpress.org/ticket/41604