This was determined by the Security team to be suitable to post publicly
CommentDefaultFormatter does not check any access control and assumes the default permissions like 'access comments' are the only access logic in play.
You can reproduce this problem by:
- Enabling the module
- Write a custom access control handler for comment entities. Use hook_entity_type_info_alter to wire up this handler for comment entities.
- Create an entity with a comment field on it. Add some comments. On the comment thread, note that the permission 'access comments' is used instead of deferring to the custom comment access control handler.
Commentary from Berdir:
The problem is that we have no concept of a "can access list of entities" operation, that simply doesn't exist and would need to be handled specially, like create access, as there is no entity to operate on/with, so we can not simply introduce a new operation.
Given that there is no "proper" way to do it, not sure if this is a security issue.
There are a few other as well, for example checking for being able to create comments, that's something we could do better. But even that sounds like a normal or maybe a security hardening bug to me.
CommentDefaultFormatter itself is also just a plugin, so if you have a case like this where you want to customize comment access, you could use a different formatter...
Many other listing pages are equally hardcoded (although this is arguably more exposed than most default (config) entity listings. The only thing that comes close to the concept of overview-access is having an admin permission, see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider::getCollectionRoute().
And last,
\Drupal\comment\CommentStorage::loadThread()implements comment_filter and entity_access (this is arguably a bit weird, since we always use ${entity_type}_access as tag. So you can for example add a condition there to deny access if the host is a certain entity or entity type.
original report:
I customized the view access logic for comments by setting my own access class. This worked for viewing a comment at comment/{comment} but not when viewing a list of comments in a comment field.
CommentDefaultFormatter does not check any access control and assumes the default permissions like 'access comments' are the only access logic in play.
Issue fork drupal-2858157
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
larowlanGoing to make this private. Will add you over there.
Comment #3
larowlanComment #4
larowlanLet's continue this in https://security.drupal.org/node/161916
Comment #6
pwolanin commentedComment #7
pwolanin commentedComment #10
a_grizzli commentedI struggled with same problem, when trying to restrict access to some type of comments. So implementing a custom access handler for comment entity only protects
comment/{comment}path, but not comment listings. In my case it was possible to adapt query in a proper way usinghook_query_alterand looking forcomment_filtertag:In general, it might be problematic to combine custom access check on single comment entity and DB queries for comment list.
Comment #11
jonathanshawI imagine #777578: Add an entity query access API and deprecate hook_query_ENTITY_TYPE_access_alter() will eventually help with this.
Comment #22
prudloff commentedI'm not sure this can be fixed in CommentDefaultFormatter.
If #777578: Add an entity query access API and deprecate hook_query_ENTITY_TYPE_access_alter() adds a generic system to alter access in entity queries, then custom code could alter access in comment queries and it would hopefully apply everywhere including in CommentStorage::loadThread().