-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix: Validate rest_route Query Var to Ensure String Type #8287
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. |
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.
I've added a note inline.
It would be helpful to add a unit test to ensure wp_die()
is called if the route is an array. For testing this patch, I used the following.
/**
* @ticket 62932
*/
public function test_rest_route_throws_wp_die_if_passed_an_array() {
$this->expectException( 'WPDieException' );
$GLOBALS['wp']->query_vars['rest_route'] = array( 'foo' => 'bar' );
rest_api_loaded();
}
If you haven't got experience with adding unit tests, I'm happy to provide assistance.
@peterwilsoncc I have added the unit-test in f14f658. Let me know if that looks good or needs some change Edit: Not sure why majority of tests are failing |
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.
I'm not sure why but this is causing seemingly unrelated tests to fail, so I will need to take a closer look at it. I hope to do so in the next week or so.
@geekofshire I think I've figured it out and it's on me, sorry 🫢 Calling Unfortunately that makes |
Hello, @peterwilsoncc Do we have any update on this on testing this change and since we need to manually test this out should I remove the unit test? Thank You! |
@geekofshire I think there are two options:
I'm happy with either option, which do you prefer? |
@peterwilsoncc I think we should move the logic above Let me know if this sounds good so I can update the PR. |
@geekofshire That sounds good, thanks. |
@peterwilsoncc Updated the approach please check once, the 2 tests are failing due to some connection issues/server config issue. |
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.
This looks great, thanks.
Just one more note about making the test clearer. If you are happy with that change, I am happy to commit it.
ab430cf
to
d965112
Compare
This PR introduces an early return validation in
rest_api_loaded(
to ensure that the rest_route query variable is always a string. If the rest_route is not a string, the function now returns aWP_Error
, allowing for better error handling and maintaining proper REST API response behaviour.Changes:
wp_die()
with aWP_Error
response to improve flexibility.Trac ticket: https://core.trac.wordpress.org/ticket/62932
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.