Make WordPress Core

Opened 10 years ago

Last modified 6 weeks ago

#38622 reopened defect (bug)

XML-RPC wp_newComment should return an error when a field exceeds the maximum length

Reported by: rachelbaker Owned by:
Priority: low Milestone: Awaiting Review
Component: XML-RPC Version: 4.5
Severity: normal Keywords: good-first-bug has-patch has-unit-tests
Cc: Focuses:

Description

We return a WP_Error in wp_handle_comment_submission() when the comment content, author name, author email, or author url exceeds the maximum length of its respective database column. See #10377.

We should do the same in the XML-RPC wp_newComment() method.

Attachments (1)

38622.diff (857 bytes ) - added by kingkero 7 years ago.

Download all attachments as: .zip

Change History (13)

#2 @desrosj
7 years ago

  • Keywords needs-patch added

#3 @desrosj
7 years ago

  • Keywords good-first-bug added
  • Priority normallow

Marking this as good first bug, but a lower priority.

@kingkero
7 years ago

#4 @kingkero
7 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

Added max lengths check via the wp_check_comment_data_max_lengths() function. Respect the $avoid_die flag with the same logic that wp_allow_comment() uses

This ticket was mentioned in PR #178 on WordPress/wordpress-develop by sorenbronsted.


7 years ago
#5

<!--
Hi there! Thanks for contributing to WordPress!

Pull Requests in this GitHub repository must be linked to a ticket in the WordPress Core Trac instance (https://core.trac.wordpress.org), and are only used for code review. No pull requests will be merged on GitHub.

See the WordPress Handbook page on using PRs for Code Review more information: https://make.wordpress.org/core/handbook/contribute/git/github-pull-requests-for-code-review/

If this is your first time contributing, you may also find reviewing these guides first to be helpful:

-->

I have applied the patch from this ticket and fixed at bug when posting a comment via xmlrpc. Anon posting was missing the content_type which resulted in an error.

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

This ticket was mentioned in PR #179 on WordPress/wordpress-develop by sorenbronsted.


7 years ago
#6

<!--
Hi there! Thanks for contributing to WordPress!

Pull Requests in this GitHub repository must be linked to a ticket in the WordPress Core Trac instance (https://core.trac.wordpress.org), and are only used for code review. No pull requests will be merged on GitHub.

See the WordPress Handbook page on using PRs for Code Review more information: https://make.wordpress.org/core/handbook/contribute/git/github-pull-requests-for-code-review/

If this is your first time contributing, you may also find reviewing these guides first to be helpful:

-->

I have applied the patch from this ticket and fixed at bug when posting a comment via xmlrpc. Anon posting was missing the content_type which resulted in an error. Fixed phpcs issues also.

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

This ticket was mentioned in PR #180 on WordPress/wordpress-develop by sorenbronsted.


7 years ago
#7

<!--
Hi there! Thanks for contributing to WordPress!

Pull Requests in this GitHub repository must be linked to a ticket in the WordPress Core Trac instance (https://core.trac.wordpress.org), and are only used for code review. No pull requests will be merged on GitHub.

See the WordPress Handbook page on using PRs for Code Review more information: https://make.wordpress.org/core/handbook/contribute/git/github-pull-requests-for-code-review/

If this is your first time contributing, you may also find reviewing these guides first to be helpful:

-->

I have applied the patch from this ticket and fixed at bug when posting a comment via xmlrpc. Anon posting was missing the content_type which resulted in an error. Fixed phpcs issues also.

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

#8 @sorenbronsted
6 years ago

  • Keywords has-unit-tests added
  • Resolutioninvalid
  • Status newclosed

Sorry that my PR messed up the this comment section. PR #180 state says 'undefined' but on https://github.com/WordPress/wordpress-develop/pull/180 it says 'all checks has passed' so the state on this ticket is not reflected correctly.

#9 @sorenbronsted
6 years ago

  • Keywords needs-testing removed
  • Resolution invalid
  • Status closedreopened

I incorrectly set wrong keywords

This ticket was mentioned in PR #194 on WordPress/wordpress-develop by sorenbronsted.


6 years ago
#10

#11 @hellofromTonya
6 years ago

  • Keywords needs-refresh added

Merge conflicts exist in the PR. Marking for refresh.

This ticket was mentioned in PR #12822 on WordPress/wordpress-develop by @amanawasthi96.


6 weeks ago
#12

  • Keywords needs-refresh removed

## 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 #178/#179/#180/#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

Note: See TracTickets for help on using tickets.