Make WordPress Core

Opened 8 years ago

Last modified 2 weeks ago

#44157 assigned defect (bug)

the comments/[id] endpoints should have the same permissions checks as the comments endpoint

Reported by: tharsheblows's profile tharsheblows Owned by: adamsilverstein's profile adamsilverstein
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: REST API Keywords: 2nd-opinion has-patch has-unit-tests dev-reviewed
Focuses: Cc:

Description

I noticed this because custom comment types don't show up on the comments endpoint but it's possible to access them via their id in comments/[comment_id].

get_item_permissions_check should do the same checks as get_items_permissions_check in WP_REST_Comments_Controller

Attachments (1)

44157.diff (3.6 KB) - added by tharsheblows 6 years ago.
For illustrative purposes only

Download all attachments as: .zip

Change History (19)

#1 @pento
7 years ago

  • Version trunk deleted

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


6 years ago

#3 @TimothyBlynJacobs
6 years ago

  • Keywords 2nd-opinion added
  • Milestone changed from Awaiting Review to Future Release

I’m really not sure what to do with this. It seems incredibly plausible that someone is making use of this functionality and as such, locking it down might break their code. However, it also could be considered an information disclosure issue.

Given that we haven't seen more reports, I'm tempted to leave this as is, but I wouldn't really be happy with that. Maybe a Make.Core post to see if people are using this functionality and address it early in the cycle?

Either way, we should make a decision.

#4 @tharsheblows
6 years ago

To recap: for general users (users who do not have the edit_posts capability) the comments endpoint only lists comments which have been approved.

It will throw an error for the whole list if there is a query on the posts (eg wp-json/wp/v2/comments?post[]=x) and the user doesn’t have permission to read one of them — ie if they can read all but one they’ll still get an error for the list. This should probably be fixed and those checks (read permission on the post and what to do if the post_id === 0) could be added to get_items with the comment simply not listed if it fails it. (It’s irrelevant here but worth noting.)

Users without the edit_posts capability cannot search comments by author or author details which makes total sense. They also cannot search by the comment type and can only view comments of the type ‘comment’ (which is also null if you’re looking in the database, they’re the same) and they can’t search for unapproved comments.

It was the comment_type check that I mentioned above — there’s no such check on the individual comment endpoint in get_item and it’s possible to iterate through them, picking up comments of all types including pingbacks and trackbacks. The attached patch illustrates this.

The absence of a way to register_comment_type makes deciding what to do a bit more difficult. If people are using custom comment types, they’re rolling their own method most likely using wp_insert_comment and, I would assume, extending the comments controller in the REST API — the alternative is iterating through the endpoint to tease out the comments of the proper type.

This seems a bit of edge case — someone using a custom comment type and then not extending the controller, and maybe it’s more correctly an edge case of an edge case, there are not a lot of people using custom comment types.

I think that almost no one would be effectively scraping all of the individual comment endpoints for use in legitimate things and there might be unintended leakage of information by people who don’t realise those are public – we should apply the same permissions to those as to the comments endpoint.

Last edited 6 years ago by tharsheblows (previous) (diff)

@tharsheblows
6 years ago

For illustrative purposes only

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


6 years ago

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


3 weeks ago
#6

  • Keywords has-patch has-unit-tests added

#7 @adamsilverstein
3 weeks ago

In 61276:

Comments: ensure unauthenticated users cannot access the single comment endpoint for notes.

Fix an issue where notes could be accessed by unauthenticated users by using the single comment REST API endpoint and passing the comment ID (/wp/v2/comments/<ID>). This fix only affects the note type.

Props adamsilverstein, peterwilsoncc, westonruter.
See #44157.

#8 @adamsilverstein
3 weeks ago

  • Owner set to adamsilverstein
  • Status changed from new to assigned

Leaving this open to consider further tightening restrictions for the single comment endpoint any custom comment type. Perhaps we can start with a "doing_it_wrong" waring in 7.0, then completely block in 7.1?

Also, we should consider backporting this fix to the 6.9 branch @peterwilsoncc.

#9 @adamsilverstein
3 weeks ago

Thanks for the bug report @tharsheblows - I inadvertently left you off the Props line in my commit message so I have added your props manually in our tool.

@adamsilverstein commented on PR #10525:


3 weeks ago
#10

@peterwilsoncc I went ahead and committed what we have. I would be in favor of backporting this to 6.9, what do you think?

@JeffPaul commented on PR #10525:


3 weeks ago
#11

FWIW I support backporting to 6.9, but defer to a proper committer review/approval there.

#12 @peterwilsoncc
2 weeks ago

  • Keywords dev-reviewed added

@adamsilverstein Approved. This looks good for backport and tests well.

#13 @adamsilverstein
2 weeks ago

Thanks @peterwilsoncc - I will get this backported.

#14 @johnbillion
2 weeks ago

@adamsilverstein Should this be milestoned for 6.9?

#15 @adamsilverstein
2 weeks ago

@adamsilverstein Should this be milestoned for 6.9?

I'm not sure - we are fixing this for Notes only in 6.9 and planning a more compete fix in a future release, maybe over two releases 7.0 and 7.1 - since changing the default behavior for other custom comment types could break plugin implementations that expect the current behavior to continue working.

#16 @adamsilverstein
2 weeks ago

@johnbillion if its helpful to have a ticket milestoned 6.9 associated with this fix, I can create a new ticket for just the Notes specific issue.

#17 @peterwilsoncc
2 weeks ago

In 61297:

Comments: ensure unauthenticated users cannot access the single comment endpoint for notes.

Fix an issue where notes could be accessed by unauthenticated users by using the single comment REST API endpoint and passing the comment ID (/wp/v2/comments/<ID>). This fix only affects the note type.

Reviewed by peterwilsoncc.
Merges [61276] to the 6.9 branch.

Props adamsilverstein, peterwilsoncc, westonruter, tharsheblows.
See #44157.

@westonruter commented on PR #10525:


2 weeks ago
#18

Committed in r61276.

Backported to 6.9 branch in r61297.

Note: See TracTickets for help on using tickets.