Problem/Motivation

When users with the "administer comments" permission go to 'admin/content/comment', they are able to see node titles for nodes that they wouldn't otherwise have permission to see (unpublished nodes, for example). While they can't access those nodes, they can still edit the associated comments using the 'edit' link.

Proposed resolution

The issue with listings of nodes, which are controlled by node access API, was taken care of by the patch from Comment #11, committed by webchick in Comment #22.

Remaining tasks

A solution needs to be found to dealing with comment editor's access to unpublished nodes. Published/unpublished access control is part of hook_node_access() which is only applied to single nodes.

User interface changes

None based on Patch #11; TBD for remaining problem

API changes

None based on Patch #11; TBD for remaining problem

Original report by Stella

This is public hardening issue brought to you by the security team.

Comments

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new1.84 KB

The question is whether it's good to load every node on this page. This is not a problem for performant sites, because they use entity-cache.

One advantage here is that there is no need to join the node table anymore.

dawehner’s picture

Issue tags: +Needs tests

Status: Needs review » Needs work

The last submitted patch, 904214-access-title-comments_admin.patch, failed testing.

tobiasb’s picture

Status: Needs work » Needs review
StatusFileSize
new1.96 KB
tobiasb’s picture

StatusFileSize
new4.15 KB

Display 'Access denied' for the node title and for the comment subject "FooBar ('Access denied')" without the link to node or comment.

And I added a test.

tobiasb’s picture

StatusFileSize
new4.05 KB
dawehner’s picture

Issue tags: +Needs screenshots

A screenshot would be fine here.

tobiasb’s picture

StatusFileSize
new41.79 KB
moshe weitzman’s picture

Er, thats really weird behavior. IMO, this node nor any of its comments should be listed to unauthorized users. The comments belong to the node and are similarly inaccessible. So the fix is to add the node_access tag to the query.

moshe weitzman’s picture

Assigned: Unassigned » moshe weitzman
Priority: Normal » Major
moshe weitzman’s picture

Issue tags: -Needs tests, -Needs screenshots
StatusFileSize
new694 bytes

This 1 line is all it takes IMO

removing needs tests tag because node access system has tests. we just weren't using node access.

tobiasb’s picture

Status: Needs review » Needs work

the last patch don#t work for me.

moshe weitzman’s picture

Status: Needs work » Needs review

You are going to have to provide more detail than that. Please elaborate. The intent of my patch is that these inaccessible comments are not shown at all. It is not Drupalish to show them but not be able to view/edit/delete. Whats the point of showing 'access denied'?

How are you restricting access? I am using the hidden node_access_test module.

tobiasb’s picture

my testuser with the permission "administer comments ... " see the comment/node title from a unpublished node and thats not what we wanted. Or in other words, I couldn#t see a different w/o the patch. And I believe addTag('node_access'); works only for selects like db_select('node', 'n').

moshe weitzman’s picture

@tobias - that unpublished use case is different than the one i was trying to fix. i was focused on nodes that were protected by the node access API. your case is not easy to solve in a performant way. the published/unpublished access control is part of hook_node_access() which is only applied to single nodes, and does not apply to a listing. A listing uses node access API. Sorry about the confusing language here. Its unfortunate.

We still need to do the patch I proposed.

agentrickard’s picture

Node access _alter queries should account for node visibility (published/unpublished). It is possible that the issue in #14 was solved by #920614: Unpublished content visible when a Node Access module is enabled.

salvis’s picture

Yes, hiding inaccessible nodes from admin/content/comment is a must.

The patch works fine with Forum Access (plus the core patch in #553944-154: Define hook_menu_get_item_alter() as a reliable hook that runs before the page is doomed).

comment/CID[/view] is already blocked, however comment/CID/edit isn't!

Is this a security hole in core?

tobiasb’s picture

StatusFileSize
new3.53 KB

Edit:

function comment_access($op, $comment) {
  global $user;

  if ($op == 'edit') {
    $node = node_load($comment->nid);
    return node_access('view', $node) && (($user->uid && $user->uid == $comment->uid && $comment->status == COMMENT_PUBLISHED && user_access('edit own comments')) || user_access('administer comments'));
  }
}
coltrane’s picture

StatusFileSize
new4.37 KB

#18 updated with node_access() check for edit. Patch works great.

salvis’s picture

Status: Needs review » Needs work

The snippet in #18 looks good.

However, you're eliminating rows after the pager query, which means you end up with less than 50 (possibly even zero!) rows per page.

salvis’s picture

Status: Needs work » Reviewed & tested by the community

We got side-tracked here. We should at least commit moshe's patch in #11.

The rest can be dealt with later.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Ok, #11 committed to HEAD.

Back to.. needs work?

salvis’s picture

Title: Users with 'administer comments' should not be able to see the title of nodes they don't have access to » Users with 'administer comments' should not be able to see the titles of unpublished nodes nor view/edit their comments

Thanks! Yes.

My grasp of the unpublished situation is still not good enough to deal with this. The first priority should be to get this to work correctly without any node access module. What is correct behavior?

Probably to block view/edit of all comments of unpublished nodes that are not visible to the user. Taking into account the 'view' accessibility of the nodes (which includes published state) in listings should be necessary and sufficient. If the NA modules implement this correctly, then it should work with them, too.

Could this be as easy as adding $query->addTag('node_access'); to the comment query in comment_admin_overview()? How does core restrict the listing of unpublished nodes?

More questions than answers and no time right now...

Tor Arne Thune’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7
Bojhan.core’s picture

Priority: Major » Normal
Issue tags: +Needs issue summary update

A normal bug?

salvis’s picture

You could call it a sechole, too...

Did #11 make it into D7?

agentrickard’s picture

Yes. It's in 7.7.

dawehner’s picture

+++ modules/comment/comment.admin.inc	14 Nov 2010 20:53:27 -0000
@@ -71,33 +71,33 @@ function comment_admin_overview($form, &
+    if (node_access('view', $nodes[$comment->nid]) === FALSE) {

I'm not sure about d7 but shouldn't we load the full user as well? Wait shouldn't this be the current user looking at the list of nodes?

+++ modules/comment/comment.module	14 Nov 2010 20:53:27 -0000
@@ -1397,7 +1397,9 @@ function comment_access($op, $comment) {
+    return node_access('view', $node) && (($user->uid && $user->uid == $comment->uid && $comment->status == COMMENT_PUBLISHED && user_access('edit own comments')) || user_access('administer comments'));

I'm wondering whether it would make sense to lazy-load the node only when the other access checks are TRUE

+++ modules/comment/comment.test	14 Nov 2010 20:53:27 -0000
@@ -1021,6 +1021,21 @@ class CommentApprovalTest extends Commen
+    // Check node access

It would be probably easier to understand if there would be a comment what exactly is the issue here.

-3 days to next Drupal core point release.

TransitionKojo’s picture

Issue summary: View changes

Updating the issue summary to reflect the current state of the issue; patch from Comment #11 is already committed

TransitionKojo’s picture

Issue summary: View changes

formatting change

hefox’s picture

Based on IRC discussion, the current security stance is that users do not need to be able to see a node to be able view/edit/delete a comment on it. This very much surprised me.

Opened the broader issue #1781766: Enforce that a user must be able to view a node to view/edit/delete the comments of that node to try and change that stance so that view/edit/etc. a comment is depending on ability to view the node.

hefox’s picture

Issue summary: View changes

Updated Issue Summary using the Issue Summary Template

mgifford’s picture

Assigned: moshe weitzman » Unassigned
jonathanshaw’s picture

Status: Needs work » Closed (won't fix)

Patch in #11 is committed, current security policy is to allow editing of comments on a node without permission for the node, discussion of this has moved to #1781766: Enforce that a user must be able to view a node to view/edit/delete the comments of that node, therefore close this issue as won't fix.

mgifford’s picture

jonathanshaw’s picture