[41604] SETTINGS REST API Fix: Validate parameters in wp/v2/settings endpoint to prevent incorrect responses #8914
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trac: https://core.trac.wordpress.org/ticket/41604
Problem
The /wp/v2/settings endpoint currently accepts POST requests with empty bodies or invalid parameters and incorrectly returns the site settings instead of proper error responses.
Current behavior (incorrect):
POST /wp/v2/settings with empty body → Returns settings (should be 400)
POST /wp/v2/settings with {"invalid_param": "value"} → Returns settings (should be 400)
POST /wp/v2/settings with {"title": "New", "invalid_param": "value"} → Returns settings (should be 400)
Root Cause
The WordPress REST API args validation system only validates known parameters defined in the schema. When no settings are registered with show_in_rest => true, or when unknown parameters are provided, the validation framework doesn't reject the request, allowing the update_item() callback to execute and return settings data.
Solution
Added parameter validation in the update_item() method of
WP_REST_Settings_Controller
to:Reject empty request bodies - POST/PUT/PATCH requests must contain parameters
Reject invalid parameters - Only allow parameters that correspond to registered settings
Return appropriate HTTP 400 errors with descriptive messages
Expected Behavior After Fix