Skip to content

REST API: Only let a reaction's author delete it - #15383

Closed
adamsilverstein wants to merge 4 commits into
WordPress:trunkfrom
adamsilverstein:fix/note-reaction-delete-author-only
Closed

adamsilverstein wants to merge 4 commits into
WordPress:trunkfrom
adamsilverstein:fix/note-reaction-delete-author-only

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Claude put together this backport and its description:

Only a reaction's author can delete it now, and nobody can delete a reaction while its thread is resolved. Since r65038, anyone who can edit the note's post could remove someone else's reaction, including the post author and administrators.

This brings over the PHP changes from WordPress/gutenberg#85415. The JS change in that PR (the reaction tooltip querying approved reactions only) arrives with the package update.

Why

  • A reaction speaks for its author, the same way a note does. Letting an editor remove someone else's ❤️ changes what that person said.
  • Adding a reaction to a resolved thread is already rejected in create_item(), but removing one was not, so a stale editor tab could still change a resolved thread.

What changed

  • WP_REST_Comments_Controller::delete_item_permissions_check(): after the existing edit check passes, a reaction can only be deleted by its author, and not while its thread is resolved. Both return rest_cannot_delete.
  • The thread-root walk moves out of create_item() into a private is_thread_resolved() helper so create and delete share it. No behavior change on create.
  • Tests:
    • test_cannot_delete_another_users_reaction (post author and administrator)
    • test_cannot_delete_reaction_on_resolved_thread (root note and reply)

The existing reaction delete tests still pass, including test_moderator_cannot_delete_reaction from r65038. The four new cases fail without the fix.

Testing

  1. As user A (an editor), add a note to a post and react to it with ❤️.
  2. As an administrator, try to delete A's reaction from the editor console: wp.apiFetch( { path: '/wp/v2/comments/REACTION?force=true', method: 'DELETE' } ).catch( console.log ). Expect a 403 rest_cannot_delete. On trunk it returns 200.
  3. As A, resolve the thread, then try to remove your own reaction the same way. Expect a 403.
  4. Reopen the thread. Removing your reaction works again.

Or run phpunit --filter WP_Test_REST_Comments_Controller.

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

AI Use

Ported from the Gutenberg PR with 🤖 Claude Code, code and description both. I will review and test.


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.

🤖 Generated with Claude Code

https://claude.ai/code/session_018vwYjTXU324rGneSjaye87

A reaction speaks for its author, so being able to edit the note's post is no longer enough to remove someone else's. Reactions on a resolved thread are also frozen for deletion, matching the existing check on create. The thread-root walk moves into a shared is_thread_resolved() helper.

This brings over the PHP changes from WordPress/gutenberg#85415.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018vwYjTXU324rGneSjaye87
@github-actions

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

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

Props adamsilverstein, mamaduka, ramonopoly.

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

See #66447.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018vwYjTXU324rGneSjaye87
@ramonjd

ramonjd commented Nov 3, 2026

Copy link
Copy Markdown
Member

Code matches WordPress/gutenberg#85415

Retested the scenarios

Case Result
Admin deletes an editor's reaction 403 rest_cannot_delete
Author deletes their own reaction on a resolved thread 403 rest_cannot_delete
Author deletes their own reaction after the thread is reopened 200

);
}

if ( 'reaction' === $comment->comment_type ) {

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.

Just checking, do we need to strtolower here for the same reasons as in WordPress/gutenberg#85883 (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.

Thanks, @ramonjd. Fixed in 37c18ad.

Mirrors check_edit_permission(), so a case-variant reaction type can't skip the author-only and resolved-thread checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wporg-sync pushed a commit that referenced this pull request Nov 3, 2026
Since r65038, deleting a note reaction goes through the same `edit_comment` check as its note, so anyone who can edit the note's post, including the post author and administrators, could remove someone else's reaction. A reaction speaks for its author, so `WP_REST_Comments_Controller::delete_item_permissions_check()` now only allows its author to delete it.

Reactions on a resolved thread also can no longer be deleted, matching the existing check in `create_item()`. The thread-root walk moves into a private `is_thread_resolved()` helper shared by both.

The reaction type is matched case-insensitively, like in `check_edit_permission()`.

Developed in: #15383
Developed in: WordPress/gutenberg#85415

Follow-up to r64488, r65038.

Props adamsilverstein, ramonopoly, mamaduka.
Fixes #66447.

git-svn-id: https://develop.svn.wordpress.org/trunk@65222 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

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

SVN changeset: 65222
GitHub commit: 2a7b5ed

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 3, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 3, 2026
Since r65038, deleting a note reaction goes through the same `edit_comment` check as its note, so anyone who can edit the note's post, including the post author and administrators, could remove someone else's reaction. A reaction speaks for its author, so `WP_REST_Comments_Controller::delete_item_permissions_check()` now only allows its author to delete it.

Reactions on a resolved thread also can no longer be deleted, matching the existing check in `create_item()`. The thread-root walk moves into a private `is_thread_resolved()` helper shared by both.

The reaction type is matched case-insensitively, like in `check_edit_permission()`.

Developed in: WordPress/wordpress-develop#15383
Developed in: WordPress/gutenberg#85415

Follow-up to r64488, r65038.

Props adamsilverstein, ramonopoly, mamaduka.
Fixes #66447.
Built from https://develop.svn.wordpress.org/trunk@65222


git-svn-id: http://core.svn.wordpress.org/trunk@64371 1a063a9b-81f0-0310-95a4-ce76da25c4cd
arshidkv12 pushed a commit to arshidkv12/wordpress-develop that referenced this pull request Nov 21, 2026
Since r65038, deleting a note reaction goes through the same `edit_comment` check as its note, so anyone who can edit the note's post, including the post author and administrators, could remove someone else's reaction. A reaction speaks for its author, so `WP_REST_Comments_Controller::delete_item_permissions_check()` now only allows its author to delete it.

Reactions on a resolved thread also can no longer be deleted, matching the existing check in `create_item()`. The thread-root walk moves into a private `is_thread_resolved()` helper shared by both.

The reaction type is matched case-insensitively, like in `check_edit_permission()`.

Developed in: WordPress#15383
Developed in: WordPress/gutenberg#85415

Follow-up to r64488, r65038.

Props adamsilverstein, ramonopoly, mamaduka.
Fixes #66447.

git-svn-id: https://develop.svn.wordpress.org/trunk@65222 602fd350-edb4-49c9-b593-d223f7449a82
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.

3 participants