XML-RPC: Convert client-supplied dates before calling IXR_Date methods. - #13517
josephscott wants to merge 3 commits into
Conversation
Six methods called getIso() or getTimestamp() on client-supplied date values, assuming they were IXR_Date objects. A client sending a date as a string, array, or other type caused a fatal error. A new wp_xmlrpc_server::_convert_client_date() helper passes an IXR_Date through, converts a string the same way wp.newPost already did, and returns a 400 IXR_Error for anything else. It is used in _insert_post(), wp.editPost, wp.editComment, metaWeblog.newPost, and metaWeblog.editPost. See #66107, #42995. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
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.
What may make sense is to start adopting JSON Schema for the XML-RPC methods. It could re-use REST API functions to validate and sanitize the incoming data. This would eliminate a lot of ad hoc type checking. Maybe this is out of scope here.
| @@ -1365,15 +1389,15 @@ public function wp_newPost( $args ) { | |||
| } | |||
There was a problem hiding this comment.
I think this warrants adding a type check for the $content_struct. Something like this:
| } | |
| } | |
| if ( ! is_array( $content_struct ) ) { | |
| return new IXR_Error( 400, __( 'Invalid parameters.', 'xmlrpc-server' ) ); | |
| } |
There was a problem hiding this comment.
Same goes for wp_editPost below.
There was a problem hiding this comment.
I've added a _is_content_struct_array() helper method to check for this. It is now applied in the places where we expect that struct, and tests against those.
|
|
||
| // If the post has been modified since the date provided, return an error. | ||
| if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['if_not_modified_since']->getTimestamp() ) { | ||
| if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $if_not_modified_since->getTimestamp() ) { |
There was a problem hiding this comment.
Also, what if $post['post_modified_gmt'] is not a string?
There was a problem hiding this comment.
I've applied string checks to dates and added tests for those conditions.
Check to make sure we got a struct in the places they are expected
https://core.trac.wordpress.org/ticket/66107
AI assistance: Yes
Tool(s): Claude Code
Model(s): Fable 5.1
Used for: Research and experimentation. Guided directions on writing the code changes. It wrote the tests.
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.