Skip to content

Comments: Harden reaction and note permissions. - #15853

Closed
adamsilverstein wants to merge 33 commits into
WordPress:trunkfrom
adamsilverstein:fix/harden-note-reaction-permissions
Closed

adamsilverstein wants to merge 33 commits into
WordPress:trunkfrom
adamsilverstein:fix/harden-note-reaction-permissions

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

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

Hardens the note and reaction comment types so the request handlers that write comments apply the rules the REST API already enforces for them.

The low-level comment functions (wp_insert_comment(), wp_new_comment(), wp_update_comment()) are left alone, the checks live in the handlers that take user input.

Claude rewrote this summary to match the code after the latest review rounds:

A reaction belongs to its author, carries one of the curated emoji keys and sits under a note on the same post. Only WP_REST_Comments_Controller enforces that today. wp_ajax_replyto_comment(), edit_comment() and wp.editComment predate the two types and apply none of it, and the reaction_summary field added in 7.2 reads the rows back as they are.

Changes:

  • wp_ajax_replyto_comment() refuses note and reaction types and limits the type to lowercase ASCII key characters, since the comment_type collation is case- and accent-insensitive. It also drops a parent comment that is on a different post.
  • edit_comment() refuses to edit a reaction. When a comment moves to another post, a parent it keeps has to be on the destination post too.
  • wp.editComment refuses to edit a reaction.
  • WP_REST_Comments_Controller::create_item() requires a note reply's parent to be a note on the same post.
  • prefetch_reaction_summaries() joins the parent note on the same post, allow-lists get_note_reaction_keys() and accumulates counts.
  • The comments schema declares 'minimum' => 0 on the item's parent and post and on the parent collection parameter. wp-api-generated.js is regenerated to match.

Not changed:

  • wp_insert_comment(), wp_new_comment() and wp_update_comment() behave as they do in trunk. Code calling them directly can still store any row; the summary query ignores reactions that are not on their note's post or do not use a curated key.
  • Type changes and moving a comment or note to another post follow the checks already in trunk (_wp_check_comment_target_post() and the REST target post check). This PR adds nothing there.
  • reaction_summary still counts rows with user_id 0 and duplicate rows from one user.

Known gaps, confirmed with throwaway tests and left for follow up:

  • A REST update can still set a note's parent to a note on another post. The same-post rule is only applied on create. Trunk behaves the same way.
  • Moving a note to another post leaves its reactions on the original post, so they drop out of reaction_summary until the note moves back. Trunk counts them by parent alone.
  • The type guards compare 'reaction' exactly. A row stored with another spelling such as Reaction, which only code calling the low-level functions (or the reply handler before this change) could write, is counted by the summary query but can still be edited.
  • On a case-insensitive collation the summary groups 1f680 and an uncurated 1F680 together, and the valid reaction can be dropped with the invalid one. The REST API always stores the lowercase key.

Tests are tagged with the Trac ticket and cover the ajax reply and edit handlers, wp.editComment, and the REST create and summary paths, plus one asserting wp_update_comment() stays unrestricted.

How has this been tested

  • vendor/bin/phpunit --group ajax --filter 'Tests_Ajax_wpAjax(Replyto|Edit)Comment'
  • vendor/bin/phpunit --group xmlrpc --filter Tests_XMLRPC_wp_editComment
  • vendor/bin/phpunit tests/phpunit/tests/comment.php
  • vendor/bin/phpunit --filter WP_Test_REST_Comments_Controller
  • PHPCS is clean on the changed lines. PHPStan level 10 has one report on them: get_comment( $parent_id ) in create_item() receives mixed, the same as the existing call a few lines below.

Commit message

Comments: Tighten note and reaction rules in all handlers.

Ensure all routes enforce that a reaction belongs to its author, carries one of the curated emoji keys and sits under a note on the same post, including Ajax and XML-RPC update routes.

Also, a note reply must have a note on the same post as its parent, and `reaction_summary` only counts reactions that are on their note's post and use a curated key.

Follow-up to [64488], [64999], [65222].

Reviewed by westonruter.

Props westonruter, wildworks, mamaduka.
Fixes #66635.

AI Use

Code, tests and this description came out of a few rounds with 🤖 Claude Code, with the direction set by me and the reviewers. I will review and test.

The reaction comment type's invariants were only enforced in the REST
comments controller. The admin-ajax reply handler accepted `comment_type`
and an unbound `comment_parent` from the request, so a user with
`edit_post` on any post could store an approved reaction under a note on a
post they cannot read. The admin-ajax, Edit Comment screen and XML-RPC
editors could then rewrite, reattribute and move reactions through
`wp_update_comment()`, which has no type guard.

Refuse note and reaction types in `wp_ajax_replyto_comment()`, drop a
parent on another post in `wp_new_comment()` the way an invalid-status
parent is already dropped, make `wp_update_comment()` refuse reactions,
and require edit access to the destination post in `edit_comment()`.

Claude-Session: https://claude.ai/code/session_018vwYjSnX8ne8xPxaUhsmSX
`prefetch_reaction_summaries()` grouped on `comment_parent` alone and used
the raw content as the key, so any approved row typed `reaction` that
pointed at a note was counted under it, and groups that stripped to the
same key overwrote one another. Join the parent note and require the
reaction to be stored on the note's post, skip keys that are not in
`get_note_reaction_keys()`, and accumulate counts.

Compare the comment type case-insensitively in the update guard, as the
database does, so a row typed `Reaction` cannot be counted as a reaction
and edited as a comment.

Claude-Session: https://claude.ai/code/session_018vwYjSnX8ne8xPxaUhsmSX
The comment type column uses a case- and accent-insensitive collation, so
a type such as `reactión` is queried as `reaction` while a `strtolower()`
comparison in PHP does not see it. Reject non-ASCII types in
`wp_ajax_replyto_comment()` so the note and reaction refusal covers every
spelling the database would match.

Claude-Session: https://claude.ai/code/session_018vwYjSnX8ne8xPxaUhsmSX
The reaction guard in wp_update_comment() only looked at the stored
type. edit_comment() passes the whole request to wp_update_comment(),
which merges comment_type and user_id, so an author could reply beneath
a note on their own post with an ordinary comment and then edit that
reply into a reaction attributed to another user. The forged row passed
the summary query because its parent is a note on the same post.

Refuse an update whose type crosses into or out of note/reaction, the
way the REST API already refuses any type change on update. Plain
comment type changes such as comment to pingback keep working.

Claude-Session: https://claude.ai/code/session_018vwYjSnX8ne8xPxaUhsmSX
The comment_type column uses a case- and accent-insensitive collation,
so a type such as "reactión" is matched by the reaction summary query
while PHP's strtolower() comparison does not see it as a reaction.
Refuse a type change whose new value contains anything outside ASCII
key characters, the same limit wp_ajax_replyto_comment() applies.

Claude-Session: https://claude.ai/code/session_018vwYjSnX8ne8xPxaUhsmSX
"$" matches before a trailing newline, so "reaction\n" passed the
pattern while failing the strtolower() comparison. Use "\z" so the
whole value has to be ASCII key characters.

Claude-Session: https://claude.ai/code/session_018vwYjSnX8ne8xPxaUhsmSX
The type guard compared lowercased values, so changing a note's type to
"NOTE" was written through. The database still matches that row as a
note, but most of core compares comment types strictly, so the row
would lose the note-specific permission and summary handling. Compare
the raw values instead and accept uppercase only for other types.

Claude-Session: https://claude.ai/code/session_018vwYjSnX8ne8xPxaUhsmSX
The reaction summary now only counts reactions stored on the note's
post, and reactions cannot be updated on their own, so moving a note to
another post would strand its reactions: hidden from the summary and
still blocking the same user from reacting again. Move them with the
note in wp_update_comment(), which both the REST API and the admin
writers go through.

Claude-Session: https://claude.ai/code/session_018vwYjSnX8ne8xPxaUhsmSX
…ent.

edit_comment() skipped the destination check for a post ID of zero,
which detached the comment from its post and from the post's
capability mapping. It also validated a new parent against the post the
comment was leaving, and never checked the parent a moved comment kept,
so a comment could end up threaded under a comment on another post.

Fetch the comment once, refuse a zero or missing destination post, and
require any parent, new or kept, to be on the post the comment will be
on.

Claude-Session: https://claude.ai/code/session_018vwYjSnX8ne8xPxaUhsmSX
The value is trimmed first, so "$" was safe here, but use "\z" like
wp_update_comment() so the two copies of the rule stay identical.

Claude-Session: https://claude.ai/code/session_018vwYjSnX8ne8xPxaUhsmSX
create_item() only validated the parent of reactions, so a user could
thread a note of their own under a note on a post they cannot read by
naming it as the parent while targeting a post they can edit. Notes
are inserted through wp_insert_comment(), so the wp_new_comment()
guard does not cover them.

Claude-Session: https://claude.ai/code/session_018vwYjSnX8ne8xPxaUhsmSX
@github-actions

github-actions Bot commented Nov 9, 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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein, westonruter, wildworks, mamaduka.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

github-actions Bot commented Nov 9, 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.

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR!

Relaxing a strict rule later is easy, but tightening a loose one after release is hard. Reactions may be attached to regular comments in the future, but for now it seems best to keep the rules as strict as possible.

I haven't reviewed the code in detail yet. Below is an AI-assisted analysis of how each write path behaves for reactions before and after this PR. The three rows marked 🤔 are points that may need changes, and all of them look reasonable to me.

Path: scenario Reaction (before) Reaction (after)
REST create: set another user as the author Rejected. Specifying another user as author returns an error. The author is also overwritten with the current user on save No change
REST create: emoji key not in the allowed list Rejected. Anything other than the 7 allowed keys (get_note_reaction_keys()) returns an error No change
REST create: parent on a different post Rejected. Returns an error if the parent note's post differs from the request's post No change
REST create: parent of the wrong type Rejected. Returns an error if the parent is not a note No change
REST update: any edit (including author, parent, post and type changes) Partial. Reaction updates are refused, but the type is compared with ===, so a row with uppercase letters such as Reaction is treated as a regular comment and can be updated Rejected. The type is compared in lowercase, so Reaction rows are refused too. The lower-level wp_update_comment() also refuses reaction updates
ajax reply: create a note or reaction Pass. comment_type can be set freely from the request, so reactions can be created Rejected. Refused when the type is note or reaction (case-insensitive), or contains characters other than letters, digits, _ and -
ajax reply: set another user as the author Rejected. The author is always the current user No change
ajax reply: emoji key not in the allowed list Pass. Any string can be saved as the content Rejected. Reactions can no longer be created via ajax
ajax reply: parent on a different post Pass. Only the parent's status is checked Rejected. Reactions can no longer be created via ajax
ajax reply: parent of the wrong type Pass. The parent's type is not checked Rejected. Reactions can no longer be created via ajax
edit_comment(): change the author ($_POST['user_id'] etc.) Pass. user_id and other fields in $_POST are saved as is Rejected. The lower-level wp_update_comment() refuses all reaction updates
edit_comment(): change the content Pass. The content can be rewritten to any string Rejected. The lower-level wp_update_comment() refuses all reaction updates
edit_comment(): change the parent Partial. Checks that the new parent has the same type and is on the same post. But when the post is changed at the same time, the check uses the post the comment is leaving Rejected. The lower-level wp_update_comment() refuses all reaction updates
edit_comment(): move to another post Pass. Edit permission on the destination post is not checked. The post can even be set to 0 Rejected. The lower-level wp_update_comment() refuses all reaction updates
edit_comment(): change the type Pass. comment_type can be changed to any value Rejected. The lower-level wp_update_comment() refuses all reaction updates
wp.editComment: change the content, author name or email Pass. The content can be rewritten to any string, and the author name and email to someone else's Rejected. The lower-level wp_update_comment() refuses all reaction updates
wp_update_comment() directly: change a reaction Pass. Saved without any validation Rejected. Updating a reaction returns a comment_reaction_immutable error (remove and re-add instead)
wp_update_comment() directly: change the type Pass. Can be changed to any type Rejected. Changing to or from note/reaction returns a comment_type_immutable error
wp_update_comment() directly: parent and post consistency Pass. The parent and post combination is not validated Rejected. Reactions cannot be updated at all
wp_update_comment() directly: move a note to another post Pass. When a note is moved to another post, its reactions stay on the original post and keep being counted in the summary 🤔 When a note is moved to another post, the post of its child reactions is rewritten too. However, this only applies when the moved comment is a note. Suggestion: to allow for reactions on regular comments in the future, move child reactions along with any comment that moves to another post, regardless of the parent's type
wp_insert_comment() directly: all fields Pass. Nothing is validated 🤔 No change. Suggestion: when a plugin or other code saves a reaction directly without going through REST, refuse to save it unless it meets the same rules as REST (the parent is a note on the same post, and the emoji is in the allowed list)
reaction_summary read: reaction rows on a different post Pass. Counts by parent ID only, so reaction rows on other posts are counted too Rejected. Joins the parent note and counts only rows where the reaction and its parent note are on the same post
reaction_summary read: keys not in the allowed list Pass. Disallowed keys appear in the summary as is Rejected. Keys outside the allowed list are excluded from the counts
reaction_summary read: inconsistent author (user_id 0 etc.) Pass. Rows with user_id = 0 and duplicate rows from the same user are counted 🤔 No change. Suggestion: skip rows with an unknown author, and count duplicate rows from the same user once (one vote per user per key)

@t-hamano

Copy link
Copy Markdown
Contributor

P.S. Should we publish a 7.2 dev note to explain how the reaction comment type is handled across the various APIs?

@Mamaduka

Copy link
Copy Markdown
Member

I'm not really sure about changes for APIs like wp_update_comment; usually, similar low-level APIs don't have restrictions like this in WordPress.

@adamsilverstein

Copy link
Copy Markdown
Member Author

I'm not really sure about changes for APIs like wp_update_comment; usually, similar low-level APIs don't have restrictions like this in WordPress.

I agree we should let this function behave with limited restrictions. having access to that function implies the user already has direct access to code and can do whatever they want including direct database manipulation.

P.S. Should we publish a 7.2 dev note to explain how the reaction comment type is handled across the various APIs?

Probably worth a dev note for reactions. +1

🤔 When a note is moved to another post, the post of its child reactions is rewritten too. However, this only applies when the moved comment is a note. Suggestion: to allow for reactions on regular comments in the future, move child reactions along with any comment that moves to another post, regardless of the parent's type

I would favor preventing notes from being moved to another post int he first place, thats not something we support currently; we can reconsider if we want to change that later. For now that sees simpler than trying to move all of the chile reactions.

wp_insert_comment() directly: all fields
🤔 No change. Suggestion: when a plugin or other code saves a reaction directly without going through REST, refuse to save it unless it meets the same rules as REST (the parent is a note on the same post, and the emoji is in the allowed list)

As discussed above, lets not add restrictions to wp_insert_comment

🤔 No change. Suggestion: when a plugin or other code saves a reaction directly without going through REST, refuse to save it unless it meets the same rules as REST (the parent is a note on the same post, and the emoji is in the allowed list)

same.

reaction_summary read: inconsistent author (user_id 0 etc.)
🤔 No change. Suggestion: skip rows with an unknown author, and count duplicate rows from the same user once (one vote per user per key)

Feels outside scope of this pr, will review.

Low-level writers stay unrestricted, as elsewhere in core. The request
handlers that take user input, edit_comment(), wp.editComment and the
REST controller, refuse reaction edits and type changes themselves.
Notes can no longer be moved to another post through those handlers,
which replaces moving their reactions along with them.
wp_new_comment() goes back to its trunk behavior, in keeping with
leaving the core comment functions unrestricted. The reply handler
is the writer that takes the parent from the request.
@adamsilverstein

adamsilverstein commented Nov 10, 2026 •

Copy link
Copy Markdown
Member Author

@t-hamano here is a first pass at the dev note you suggested. I also pushed changes so the low-level functions are left unrestricted and the checks sit in the request handlers instead; the description is updated to match.

I had Claude draft the dev note from the code as it stands in this PR, then I edited it a bit:

Note reactions in WordPress 7.2

WordPress 7.2 lets users react to notes with an emoji. Reactions are stored as comments with a new reaction comment type, next to the note type added in 6.9.

How a reaction is stored

Field Value
comment_type reaction
comment_parent The ID of the note being reacted to
comment_post_ID The same post as the note
user_id The user who reacted
comment_content The emoji's hex key, eg. 2764
comment_approved 1

Seven emoji are supported: 1f44d (thumbs up), 2795 (plus), 2764 (heart), 1f389 (celebration), 1f604 (smile), 1f440 (eyes) and 1f680 (rocket). This is intentionally limited and will become extensible in a future release. A full emoji picker is also being considered.

REST API

Reactions are created and removed through the existing comments endpoint.

POST /wp/v2/comments
{ "type": "reaction", "post": 123, "parent": 456, "content": "2764" }

The endpoint applies these rules:

  • The author is always the current user. Passing another user as author is an error.
  • The parent must be a note on the same post, and not trashed, spam or resolved.
  • The content must be one of the seven keys (rest_comment_invalid_reaction).
  • A user can add each emoji once per note (rest_comment_duplicate_reaction, status 409).
  • Reactions cannot be updated (rest_comment_update_not_allowed). To change one, remove it and add another.
  • Only the author can remove a reaction, and not from a resolved note.

Notes gain a reaction_summary field, keyed by emoji:

"reaction_summary": {
  "2764": { "count": 3, "current_user_reaction": 789 }
}

current_user_reaction is the ID of the current user's reaction for that emoji, or 0. The summary only counts approved reactions that are on their note's post and use one of the seven keys.

Queries and lifecycle

  • WP_Comment_Query leaves out reaction comments, as it does note, unless the type is requested explicitly or type is all. The Comments screen and get_lastcommentmodified() leave them out too.
  • Deleting a note deletes its reactions, and trashing a note trashes them. Restoring the note does not restore its reactions.

Other ways of writing comments

The older request handlers now refuse to work around these rules:

  • The admin reply handler (wp_ajax_replyto_comment()) does not create note or reaction comments.
  • edit_comment() and the XML-RPC wp.editComment method do not edit reactions.
  • edit_comment() does not change a comment's type into or out of note or reaction.
  • A note cannot be moved to another post through edit_comment() or the REST API.

The low-level functions wp_insert_comment(), wp_new_comment() and wp_update_comment() are not restricted, in keeping with other low-level APIs in core. A plugin that writes notes or reactions with them directly is responsible for keeping the rows consistent: a reaction should have a note as its parent, sit on that note's post, belong to a real user and hold one of the seven keys. A reaction on a different post from its note, or with another key, is stored but does not show up in reaction_summary.

Comment thread src/wp-admin/includes/ajax-actions.php Resolved
Comment thread src/wp-admin/includes/comment.php Resolved
Comment thread src/wp-admin/includes/comment.php Resolved
Comment thread src/wp-admin/includes/comment.php Resolved
Comment thread src/wp-admin/includes/comment.php Resolved
Comment thread src/wp-admin/includes/comment.php Resolved
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Dropping strtolower() from the note and reaction check let 'Note' and
'Reaction' through, because the type pattern was case-insensitive. The
collation treats those as the built-in types, so the handler created the
rows it is meant to refuse.

The pattern is now case-sensitive, which keeps the check free of
strtolower(). A reply with an uppercase custom type is refused too.

See #66635.

Claude-Session: https://claude.ai/code/session_018vwYjSZR5rD8K6SgpLNQFg
The refusals added for notes and reactions died with the default 500,
which reads as a server fault rather than a denied request.

The post ID comparison also casts with (int) like the assignment below
it, so a negative ID is no longer compared as its absolute value.

See #66635.

Claude-Session: https://claude.ai/code/session_018vwYjSZR5rD8K6SgpLNQFg
A double-quoted literal is read as an identifier under ANSI_QUOTES and
in SQLite, so the join would fail there. The PHP string is double-quoted
instead, which still avoids escaping.

The parent ID list is appended straight from $wpdb->prepare(), so no
interpolated variable sits between the prepare call and the query.

See #66635.

Claude-Session: https://claude.ai/code/session_018vwYjSZR5rD8K6SgpLNQFg
# Conflicts:
#	src/wp-admin/includes/comment.php
Trunk now checks the destination post and refuses type changes in
edit_comment(), and lets a note move to a post that supports notes.
Drop the overlapping checks and the note-move refusals in edit_comment()
and the REST API, keeping the reaction and kept-parent checks trunk
lacks.
Comment thread src/wp-admin/includes/comment.php Resolved
Comment thread src/wp-admin/includes/comment.php Resolved
adamsilverstein and others added 5 commits November 23, 2026 09:44
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Core only ever writes the lowercase `reaction` type, and the request handlers no longer accept any other spelling, so the case-insensitive guard only covered rows written directly through the low-level functions, which are out of scope here. Dropping it keeps the REST update check as it is in trunk and the changeset smaller.

The test for a `Reaction` row goes with it.

Claude-Session: https://claude.ai/code/session_018vwYjTrHd5zg7SWqP62gDY
…he item.

A minimum of 1 on the `parent` collection parameter rejects `parent=0`, which is how top level comments are requested, for example by the Comment Template block. `test_get_note_with_children_link` fails with a 400 as a result.

Use a minimum of 0 there, and declare the same minimum on the item's `parent` and `post` so a negative ID is refused by the schema. Both default to 0, so 0 has to stay valid. The QUnit fixture is regenerated to match.

Claude-Session: https://claude.ai/code/session_018vwYjTrHd5zg7SWqP62gDY
A real request only carries slashed strings, so integer IDs in `$_POST` let a handler pass a check it would fail in production. Name the heart reaction key, which was an unexplained literal.

Add a test for moving a reply to another post while detaching it from its parent, the one path where the submitted parent rather than the stored one decides whether the move is allowed.

Claude-Session: https://claude.ai/code/session_018vwYjTrHd5zg7SWqP62gDY
The bare `2764` literal does not say what it stands for. The constant covers the tests added here; the older tests in the file keep the literal to avoid churn.

Claude-Session: https://claude.ai/code/session_018vwYjTrHd5zg7SWqP62gDY
@adamsilverstein

adamsilverstein commented Nov 23, 2026 •

Copy link
Copy Markdown
Member Author

Thanks for the thorough second pass @westonruter! I applied your suggestions as a batch and dropped the remaining strtolower() calls to keep the changeset small. A few things came up along the way that are worth a look.

Claude worked through the follow-ups, here is what it ran into:

The schema minimum is now 0 rather than 1 (ed7aaa4). 789bc4a put 'minimum' => 1 on the parent collection parameter, and that rejects parent=0, which is how top level comments are requested, eg. by the Comment Template block. test_get_note_with_children_link fails with a 400 with the minimum at 1 and passes at 0.

The same 'minimum' => 0 is now on the item's parent and post as well, since those are the values create_item() reads. Both default to 0, so 0 has to stay valid there too. wp-api-generated.js is regenerated to match.

$kept_parent: edit_comment() already runs $_POST['comment_parent'] = (int) $_POST['comment_parent'] a few lines up, so by that point the value is an int and is_int() and is_numeric() behave the same. The path that had no coverage is a reply that moves to another post while the same request detaches it from its parent. 7ec614d adds test_can_move_reply_to_another_post_when_detached_from_its_parent for it.

PHPStan: with the is_int() check gone, level 10 reports get_comment( $parent_id ) in create_item() as receiving mixed. The existing get_comment( $request['parent'] ) further down has the same report in trunk, so it is left as suggested.

strtolower(): 2cb2d8a removes it from wp.editComment and puts the REST update check back to how it is in trunk, along with the test for a Reaction row.

Does a minimum of 0 work for you, or did you have something else in mind for the collection param?

I've asked Clause to stop adding these questions at the end which it seems to like to do to copy my style.

@westonruter

Copy link
Copy Markdown
Member

Does a minimum of 0 work for you, or did you have something else in mind for the collection param?

Yeah, that's fine. Now that it's doing a truthy check, it will work with either null or 0.

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

Changes in src look good to me. I skimmed changes in tests.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical authorization gaps still let post editors rewrite other users’ mixed-case legacy reactions and attach notes to threads on posts they cannot edit.

5 open issues
What changed in this PR

This PR hardens WordPress’s comment request handlers for editorial notes and reactions while leaving low-level comment-writing functions unrestricted.

Changes:

  • Restricts Ajax comment creation and blocks reaction edits through admin and XML-RPC handlers.
  • Adds parent/post validation, nonnegative REST ID constraints, and filtering and accumulation of reaction summaries.
  • Adds regression tests and updates the generated REST schema fixture.
File Description
tests/​qunit/​fixtures/​wp-api-generated.js Updates mocked REST schema constraints.
tests/​phpunit/​tests/​xmlrpc/​wp/​editComment.php Tests rejection of reaction edits through XML-RPC.
tests/​phpunit/​tests/​rest-api/​rest-comments-controller.php Tests note reply validation and reaction summaries.
tests/​phpunit/​tests/​comment.php Verifies low-level reaction updates remain unrestricted.
tests/​phpunit/​tests/​ajax/​wpAjaxReplytoComment.php Tests restricted types and cross-post reply handling.
tests/​phpunit/​tests/​ajax/​wpAjaxEditComment.php Tests reaction edits, type changes, and comment moves.
src/​wp-includes/​rest-api/​endpoints/​class-wp-rest-comments-controller.php Validates note parents and filters reaction summaries.
src/​wp-includes/​class-wp-xmlrpc-server.php Rejects reaction edits through XML-RPC.
src/​wp-admin/​includes/​comment.php Blocks reaction edits and checks retained parents when moving comments.
src/​wp-admin/​includes/​ajax-actions.php Restricts reply types and drops cross-post parents.

Review effort: Balanced

Comment thread src/wp-admin/includes/comment.php Resolved
…eter.

The regenerated `wp-api-generated.js` carried the new minimum on the `post` collection parameter instead of `parent`, so the PHPUnit jobs rewrote the file and failed the check for modified version-controlled files. This matches the fixture to what the generator test writes in CI.

Claude-Session: https://claude.ai/code/session_018vwYjTrHd5zg7SWqP62gDY
@adamsilverstein

Copy link
Copy Markdown
Member Author

I don't feel like Copilot's suggestions are valid or impactful enough to warrant further changes.

The REST API only checked on creation that a note reply answers a note on the same post, so an update could still set a parent on another post or move a reply away from its parent. Apply the same check to the parent and post an update results in.

A note's replies and reactions do not move with it, and the reaction summary only counts reactions stored on the note's post. Refuse to move a note that has either, in the REST API and on the Edit Comment screen, so a move cannot separate them and empty the summary.
…ate.

The reaction summary leaves out a reaction stored on a different post than its note, but the uniqueness check still matched it by parent and user. The user was refused a reaction they could not see or remove. Scope the check and the race cleanup to the note's post so both agree with the summary.
@adamsilverstein

Copy link
Copy Markdown
Member Author

@westonruter I added two small additional commits hardening a couple more cases, then ran some manual testing to make sure everything worked as expected. I'm going to get this committed before the next RC,

@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65750
GitHub commit: 14f13cb

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Nov 24, 2026
}

if ( 'note' === $request['type'] && $request['parent'] ) {
$parent_check = $this->check_note_parent( absint( $request['parent'] ), absint( $request['post'] ) );

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.

The absint() checks are unnecessary given the schema, no?

Comment on lines +1248 to +1249
$post_id = isset( $request['post'] ) ? absint( $request['post'] ) : (int) $comment->comment_post_ID;
$parent_id = isset( $request['parent'] ) ? absint( $request['parent'] ) : (int) $comment->comment_parent;

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 believe the absint() calls are redundant here.

Suggested change
$post_id = isset( $request['post'] ) ? absint( $request['post'] ) : (int) $comment->comment_post_ID;
$parent_id = isset( $request['parent'] ) ? absint( $request['parent'] ) : (int) $comment->comment_parent;
$post_id = isset( $request['post'] ) ? $request['post'] : (int) $comment->comment_post_ID;
$parent_id = isset( $request['parent'] ) ? $request['parent'] : (int) $comment->comment_parent;

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.

5 participants