Opened 2 days ago
Closed 28 hours ago
#66406 closed defect (bug) (fixed)
Comments: Use the note permission check when deleting reactions
| Reported by: | ramonopoly | Owned by: | ramonopoly |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | REST API | Version: | trunk |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Reactions (#64638) are stored as comments under a note and go through the /wp/v2/comments endpoint. When they were added in r64488, the intent was for reactions to be created and deleted using the same permission checks as notes: edit_post on the note's post.
Most of the controller already does this. WP_REST_Comments_Controller::check_edit_permission(), which decides who can delete a comment, sends notes through edit_comment (since r64875) but does not include reactions yet. A reaction therefore falls back to the permission rules for regular comments when it is deleted.
This patch adds reaction next to note in that check, so a reaction follows the same rules as the note it belongs to. Reactions already cannot be updated, so only deletion changes. Regular comments are not affected.
Includes a unit test.
cc @adamsilverstein
Change History (5)
This ticket was mentioned in PR #15130 on WordPress/wordpress-develop by @ramonopoly.
2 days ago
#1
@sadmansakibnadvi commented on PR #15130:
32 hours ago
#3
Tested on 7.2-beta3-64990 with real REST requests (cookie auth + nonce) and a Comment Moderator role that only has read and moderate_comments.
Before the patch the moderator gets a 200 and the reaction is deleted, even though the same user gets a 403 on the note it belongs to. With the patch it's a 403 and the reaction stays. Moderator on a regular comment, editor on their own and the admin's reaction, and contributor all behave the same before and after.
Full results on the ticket: https://core.trac.wordpress.org/ticket/66406
@ramonopoly commented on PR #15130:
29 hours ago
#4
Thanks for testing, folks!
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
What
Deleting a reaction through
/wp/v2/commentsnow uses the same permission check as the note it belongs to: edit access to the note's post.Why
Reactions were added in r64488 to use the note permission checks, and most of the controller already does.
check_edit_permission(), which decides who can delete a comment, sends notes throughedit_commentsince r64875 but doesn't include reactions yet. Deleting a reaction therefore falls back to the permission rules for regular comments. Reactions can't be updated, so deleting is the only action affected.What changed
WP_REST_Comments_Controller::check_edit_permission()treatsreactionthe same asnote.Manual testing
npm run env:cli -- cap add author moderate_comments.POST). In the block editor console, add a note, then a reaction to it (NOTEis the note's ID):REACTIONis its ID). This should return 403rest_cannot_delete. On trunk it returns 200.npm run env:cli -- cap remove author moderate_comments.Use of AI Tools
---
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.