Skip to content

XML-RPC: Convert client-supplied dates before calling IXR_Date methods. - #13517

Open
josephscott wants to merge 3 commits into
WordPress:trunkfrom
josephscott:xmlrpc/client-date-normalization
Open

josephscott wants to merge 3 commits into
WordPress:trunkfrom
josephscott:xmlrpc/client-date-normalization

Conversation

@josephscott

Copy link
Copy Markdown
Contributor

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.

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>
@github-actions

github-actions Bot commented Sep 14, 2026

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 josephscott, westonruter.

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

@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.

@westonruter westonruter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ) {
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this warrants adding a type check for the $content_struct. Something like this:

Suggested change
}
}
if ( ! is_array( $content_struct ) ) {
return new IXR_Error( 400, __( 'Invalid parameters.', 'xmlrpc-server' ) );
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for wp_editPost below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what if $post['post_modified_gmt'] is not a string?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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.

2 participants