Make WordPress Core

Opened 9 months ago

Last modified 4 months ago

#64779 new defect (bug)

Notes can be edited and deleted by other users

Reported by: mindctrl Owned by:
Priority: normal Milestone: Future Release
Component: Comments Version: 6.9
Severity: normal Keywords: has-patch has-unit-tests early
Cc: Focuses:

Description

A user with access to edit a post is able to edit the Notes of other users on that post. This happens because the edit_comment capability gets mapped to edit_post.

Example

A user with the Contributor role creates a new draft post. A user with the Administrator role leaves a Note on the post that says "Please change this to...". The Contributor user edits the Note to say "Looks good to me". Another editor/admin comes along later, sees the note, and publishes the post, believing the Note content is original.

It's also possible for the user with the Contributor role to delete the Note left by the admin user.

Notes

This mirrors the existing behavior for normal comments, but it feels like the behavior for Notes should be different considering they're used for collaboration where the history of the conversation helps understand the evolution of the content, and the mutability could lead to operational impacts.

Attachments (6)

64779-notes-cap-fix.diff​ (1.1 KB ) - added by sachinrajcp123 9 months ago.
Attached patch for review.
01-before-contributor-edits-admin-note.png​ (259.9 KB ) - added by shamimmoeen 4 months ago.
Before patch: Contributor edits the Admin's note and it saves.
02-after-contributor-edit-blocked.png​ (260.4 KB ) - added by shamimmoeen 4 months ago.
After patch: Contributor tries to edit the Admin's note and is blocked.
03-before-contributor-deletes-admin-note.png​ (204.4 KB ) - added by shamimmoeen 4 months ago.
Before patch: Contributor deletes the Admin's note.
04-after-contributor-delete-blocked.png​ (229.7 KB ) - added by shamimmoeen 4 months ago.
After patch: Contributor tries to delete the Admin's note and is blocked.
05-observation-menu-items-still-visible.png​ (251.5 KB ) - added by shamimmoeen 4 months ago.
After patch: Edit and Delete still show in the note menu even though the Contributor can't use them.

Download all attachments as: .zip

Change History (20)

#1 @westonruter
9 months ago

  • Keywords needs-patch added
  • Milestone Awaiting Review → 7.0

It does seem like users who don't have the manage_comments capability shouldn't be able to edit notes which they didn't author themselves.

#2 @adamsilverstein
9 months ago

cc: @Mamaduka

This ticket was mentioned in ​PR #11191 on ​WordPress/wordpress-develop by ​@mindctrl.


8 months ago
#3

  • Keywords has-patch has-unit-tests added; needs-patch removed

Notes (internal collaborative comments on posts) currently inherit the same capability mapping as regular comments, meaning anyone who can edit the parent post can edit or delete any note on it.

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

## Use of AI Tools
Opus 4.6 helped with this, particularly the phpunit tests.

#4 @mindctrl
8 months ago

  • Keywords needs-testing added

The existing patch here is incomplete, but also uses the incorrect capability name.

I've opened a new PR for this here: ​https://github.com/WordPress/wordpress-develop/pull/11191

#5 @ozgursar
8 months ago

  • Keywords needs-testing removed

Patch Testing Report

Patch Tested: ​https://github.com/WordPress/wordpress-develop/pull/11191

Environment

  • WordPress: 7.0-beta4-61919-src
  • PHP: 8.2.29
  • Server: nginx/1.29.4
  • Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
  • Browser: Opera
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.4
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.1

Steps taken

  1. Create a test user with Contributor role
  2. Create a draft post using the test user
  3. Add a note on the draft post using the admin user
  4. Try to change that note using the test user and confirm that note can be successfully changed with the message Note updated.
  5. Apply patch
  6. Try to edit the admin user's comment again
  7. Confirm that Sorry, you are not allowed to edit this comment. is displayed when updated.
  8. ✅ Patch is solving the problem

Expected result

  • Users who don't have the manage_comments capability shouldn't be able to edit notes which they didn't author themselves.

Screenshots/Screencast with results

Before
https://i.imgur.com/9eYFpWS.png

After
https://i.imgur.com/2fQno3v.png

#6 @audrasjb
8 months ago

  • Milestone 7.0 → 7.1

Since the PR is still a draft with change requests and as we're close to 7.0 RC1, I'm moving this to 7.1.

#7 follow-up: @manfcarlo
8 months ago

I think the pre-existing behaviour (any user able to delete any note) is correct. If someone leaves a note with profanity or personal attacks, or a typo, it should be easy for others to delete/correct without having to contact someone with higher privileges. If someone is maliciously deleting or changing other users' notes, they would be better off having their editing access to the whole post revoked.

#8 in reply to: ↑ 7 @mindctrl
6 months ago

Replying to manfcarlo:

I think the pre-existing behaviour (any user able to delete any note) is correct. If someone leaves a note with profanity or personal attacks, or a typo, it should be easy for others to delete/correct without having to contact someone with higher privileges. If someone is maliciously deleting or changing other users' notes, they would be better off having their editing access to the whole post revoked.

While I agree that malicious users should have their access revoked, it doesn't solve the problem outlined above. To restate my concern:

Since comments have no revision history, there's no way to see that a note was changed or what it originally said. A Contributor, for example, could edit an Admin's note on their own draft to say something the Admin never wrote, and anyone reviewing the post later would have no way of knowing.

This ticket was mentioned in ​Slack in #core-test by huzaifaalmesbah. ​View the logs.


4 months ago

@shamimmoeen
4 months ago

Before patch: Contributor edits the Admin's note and it saves.

@shamimmoeen
4 months ago

After patch: Contributor tries to edit the Admin's note and is blocked.

@shamimmoeen
4 months ago

After patch: Contributor tries to delete the Admin's note and is blocked.

@shamimmoeen
4 months ago

After patch: Edit and Delete still show in the note menu even though the Contributor can't use them.

#10 @shamimmoeen
4 months ago

Patch Testing Report

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/11191 (applied as a diff onto current trunk)

Environment

  • WordPress: 7.1-beta3-62828-src (trunk)
  • PHP: 8.3.32
  • Server: nginx/1.31.1
  • Database: mysqli (Server: 8.4.10 / Client: mysqlnd 8.3.32)
  • Browser: Chrome (macOS)
  • OS: macOS
  • Theme: Twenty Twenty-Three 1.6
  • MU Plugins: None activated
  • Plugins: None activated

Steps taken

Before patch (clean trunk):

  1. Created a test user with the Contributor role.
  2. As the Contributor, created a new draft post.
  3. As Admin, added a Note on the draft post ("Please change this to...") and saved the draft.
  4. As the Contributor, edited the Admin's note — the edit succeeded with the message Note updated. and the note still displayed Admin as its author.
  5. As the Contributor, deleted the Admin's note — the deletion succeeded with the message Note deleted.
  6. ❌ Confirmed the bug on current trunk: a Contributor can silently rewrite or remove an Admin's note on their own draft, with no trace.

After applying the patch (repeated on a fresh draft):

  1. As the Contributor, tried to edit the Admin's note → blocked with Sorry, you are not allowed to edit this comment.
  2. As the Contributor, tried to delete the Admin's note → blocked with Sorry, you are not allowed to delete this comment.
  3. As the Contributor, added a note of my own, then edited it → succeeded (Note updated.), confirming authors can still manage their own notes.
  4. As Admin, edited the Contributor's note → succeeded (Note updated.), confirming users with moderate_comments can still manage all notes.
  5. As Admin, deleted the Contributor's note → succeeded (Note deleted.).

Result

✅ Patch is solving the problem. Note authors and users with the moderate_comments capability retain the ability to edit and delete notes; other users can no longer edit or delete notes they didn't author.

Expected result

Users who don't have the moderate_comments capability shouldn't be able to edit or delete notes which they didn't author themselves.

Observation (UX, possible follow-up)

The Edit and Delete items still appear in the note's dropdown menu even for notes the user cannot modify. Clicking them just returns the "not allowed" message, so nothing breaks, but the options show up when they can't be used (see attached screenshot).

Screenshots

Bug reproduced on trunk, fixed by the patch:

Before (trunk) After (patched)
Contributor edits Admin's note — succeeds ("Note updated")
Before patch: Contributor edits the Admin's note and it saves.
Contributor edit blocked ("Sorry, you are not allowed to edit this comment")
After patch: Contributor tries to edit the Admin's note and is blocked.
Contributor deletes Admin's note — succeeds ("Note deleted")
Before patch: Contributor deletes the Admin's note.
Contributor delete blocked ("Sorry, you are not allowed to delete this comment")
After patch: Contributor tries to delete the Admin's note and is blocked.

Legitimate access preserved (patched, confirmed in steps above):

  • The Contributor can still edit and delete their own notes.
  • Admin (a user with moderate_comments) can still edit and delete any note.

UX observation:

Edit/Delete still appear in the dropdown for a note the Contributor cannot modify:
After patch: Edit and Delete still show in the note menu even though the Contributor can't use them.

Last edited 4 months ago by shamimmoeen (previous) (diff)

#11 @ugyensupport
4 months ago

Test Report

Patch tested:​https://github.com/WordPress/wordpress-develop/pull/11191

Environment

  • WordPress: 7.0.3-alpha-62793
  • Subdirectory: No
  • PHP: 8.4.14
  • Server: nginx/1.21.4
  • Database: mysqli (Server: 5.7.44-log / Client: mysqlnd 8.4.14)
  • Browser: Chrome 150.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.5
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.3.0
    • WordPress Beta Tester 4.0.0
    • WP File Manager 8.0.4

Steps taken

Before patch (clean trunk):

Created a test user with the Contributor role.
As the Contributor, created a new draft post.
As Admin, added a Note on the draft post ("Please change this to...") and saved the draft.
As the Contributor, edited the Admin's note — the edit succeeded with the message Note updated. and the note still displayed Admin as its author.
As the Contributor, deleted the Admin's note — the deletion succeeded with the message Note deleted.
❌ Confirmed the bug on current trunk: a Contributor can silently rewrite or remove an Admin's note on their own draft, with no trace.
After applying the patch (repeated on a fresh draft):

As the Contributor, tried to edit the Admin's note → blocked with Sorry, you are not allowed to edit this comment.
As the Contributor, tried to delete the Admin's note → blocked with Sorry, you are not allowed to delete this comment.
As the Contributor, added a note of my own, then edited it → succeeded (Note updated.), confirming authors can still manage their own notes.
As Admin, edited the Contributor's note → succeeded (Note updated.), confirming users with moderate_comments can still manage all notes.
As Admin, deleted the Contributor's note → succeeded (Note deleted.).

Expected result

  • Users who don't have the moderate_comments capability shouldn't be able to edit or delete notes which they didn't author themselves.

Result

  • The patch fixes this issue. Note authors and users with the 'moderate_comments' capability can still edit and delete notes. Other users can no longer edit or delete notes they did not author.

#12 @vedantere
4 months ago

Trac #64779 — Patch Testing Report

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/11191

Environment:
WordPress: 7.0.2
PHP: 8.5.6
Server: nginx (Local by Flywheel)
Database: mysqli
Browser: Chromium (headless, automated via REST API)
OS: macOS

Steps taken

Before patch (clean trunk):

Created a test user with the Contributor role.
Created a draft post authored by the Contributor.
As Admin, added a Note on the draft ("Please change this to something else.").
As the Contributor, edited the Admin's note via the REST API → succeeded (200), content changed.
❌ Confirmed the bug: a Contributor can rewrite an Admin's note on their own draft.

After applying the patch:

  1. As the Contributor, tried to edit the Admin's note → blocked (403 rest_cannot_edit, "Sorry, you are not allowed to edit this comment.").
  2. As the Contributor, tried to delete the Admin's note → blocked (403 rest_cannot_delete, "Sorry, you are not allowed to delete this comment.").
  3. As the Contributor, created their own note, then edited and deleted it → both succeeded (200), confirming authors retain control of their own notes.
  4. As Admin (has moderate_comments), edited and deleted a note authored by the Contributor → both succeeded (200), confirming moderators retain full access.

Result
✅ Patch is solving the problem. Note authors and users with moderate_comments retain edit/delete access; everyone else is correctly blocked from modifying notes they didn't author.

Expected result
Users who don't have the moderate_comments capability shouldn't be able to edit or delete notes they didn't author.

This ticket was mentioned in ​Slack in #core by adrianduffell. ​View the logs.


4 months ago

#14 @adrianduffell
4 months ago

  • Keywords early added
  • Milestone 7.1 → Future Release

This was discussed in today's bug scrub. It has a PR ready for review and multiple successful test reports, but I’d like to punt this since RC 1 is due in a few days time. It looks valuable to fix soon, so tagging with early for consideration in 7.2.

Note: See TracTickets for help on using tickets.