Skip to content

XML-RPC: Return an error when a comment field exceeds the maximum length - #12822

Open
amanawasthi2025 wants to merge 1 commit into
WordPress:trunkfrom
amanawasthi2025:fix/38622-xmlrpc-newcomment-max-lengths
Open

XML-RPC: Return an error when a comment field exceeds the maximum length#12822
amanawasthi2025 wants to merge 1 commit into
WordPress:trunkfrom
amanawasthi2025:fix/38622-xmlrpc-newcomment-max-lengths

Conversation

@amanawasthi2025

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/38622

What

wp_xmlrpc_server::wp_newComment() now validates the assembled comment with wp_check_comment_data_max_lengths() — after both the logged-in and anonymous flows have filled in the author fields, and before wp_new_comment() runs — and returns an IXR_Error 413 when any field exceeds its column limit (author 245, author email 100, author URL 200, content 65525 bytes).

Why

The comment form (wp_handle_comment_submission(), #10377) and the REST API comments controller both perform this validation; the XML-RPC path never did. Because wpdb strips strict SQL modes, over-long fields were silently truncated at the database layer and the client received a success response with a comment ID.

Design notes:

  • The error message reuses the REST controller's existing string (Comment field exceeds maximum length allowed.) instead of the form-path messages, which embed <strong> markup unsuitable for an XML-RPC fault string. No new translatable strings.
  • Fault code 413 follows the ticket's original 2019/2020 patches (this PR supersedes PRs Added patch from ticket 38622 #178/Added patch from ticket 38622 #179/Added patch from ticket 38622 #180/Added patch from ticket 38622 #194 and 38622.diff, which no longer apply cleanly).
  • The check runs on slashed data, matching how the form path validates wp_magic_quotes()-slashed $_POST.
  • @since 7.2.0 assumes a post-7.1 landing; adjust on commit if milestoned differently.

Tests

tests/phpunit/tests/xmlrpc/wp/newComment.php:

  • test_new_comment_with_field_exceeding_max_length (data provider: author 246 / email 101 / URL 201 / content 65526) — red on trunk without the src change: each call returns a comment ID and the field is silently truncated.
  • test_new_comment_with_content_exceeding_max_length_logged_in — same symptom via the authenticated flow.
  • test_new_comment_with_fields_at_max_length — all fields exactly at their limits are still accepted.
npm run test:php -- tests/phpunit/tests/xmlrpc/wp/newComment.php   # 28 tests, 50 assertions, OK
npm run test:php -- --group xmlrpc                                 # 324 tests, 1258 assertions, OK

PHPCS reports no issues on either changed file.

🤖 Generated with Claude Code

…gth.

The comment form (`wp_handle_comment_submission()`) and the REST API
comments controller both validate comment fields against
`wp_check_comment_data_max_lengths()` before inserting, but the XML-RPC
`wp.newComment` path never called the validator, so over-long fields
were silently truncated at the database layer instead of the client
receiving an error.

Validate the fully assembled comment in
`wp_xmlrpc_server::wp_newComment()` — covering both the logged-in and
anonymous flows — and return an `IXR_Error` 413, reusing the REST API's
existing error string.

Includes tests for each over-long field (author, author email, author
URL, content) in both flows, plus an at-the-limit acceptance case.

Fixes #38622.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 3, 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 amanawasthi96.

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

@github-actions

github-actions Bot commented Aug 3, 2026

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.

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.

1 participant