Problem/Motivation

Admin should not be able to edit email of authenticated commenters.

Proposed resolution

Fix comment field access

Remaining tasks

Patch

User interface changes

None

API changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because access
Issue priority Major because access
Prioritized changes The main goal of this issue is security.  This is a prioritized change for the beta phase.
Disruption Non disruptive

CommentFileSizeAuthor
#48 drupal-remove_email_comment_access-2398073-48-complete.patch2.75 KBgeertvd
#48 drupal-remove_email_comment_access-2398073-48-test.patch1.95 KBgeertvd
#48 interdiff.txt944 bytesgeertvd
#44 drupal-remove_email_comment_access-2398073-41-complete.patch2.5 KBmohit_aghera
#44 drupal-remove_email_comment_access-2398073-41-test.patch2.5 KBmohit_aghera
#40 drupal-remove_email_comment_access-2398073-40-complete.patch2.43 KBmohit_aghera
#40 drupal-remove_email_comment_access-2398073-40-test.patch1.63 KBmohit_aghera
#36 interdiff-2398073-32-36.txt787 bytessidharrell
#36 admin_should_not_be-2398073-36.patch2.5 KBsidharrell
#33 drupal-remove_email_comment_access-2398073-32-complete.patch2.34 KBmohit_aghera
#33 drupal-remove_email_comment_access-2398073-32-test.patch2 KBmohit_aghera
#31 drupal-remove_email_comment_access-2398073-31-complete.patch2.34 KBgeertvd
#31 drupal-remove_email_comment_access-2398073-31-test.patch1.54 KBgeertvd
#15 Screenshot from 2015-02-13 20:39:30.png24.49 KBsidharrell
#29 drupal-remove_email_comment_access-2398073-2.patch819 bytesSwarnendu-Dutta
#21 comment-admin-sdnt-be-able-edit-email-2398073-21.patch1.27 KBSwarnendu-Dutta
#29 drupal-remove_email_comment_access-2398073-2.patch819 bytesSwarnendu-Dutta
#19 comment.module-admin-should-not-access-email-of-commenters-2398073-19.patch1.72 KBSwarnendu-Dutta
#17 2398073.patch822 byteslarsmw
#15 admin_should_not_be-2398073-15.patch819 bytessidharrell
#12 author-and-email-changed.png30.25 KBpiggito
#12 author-change.png34.12 KBpiggito
#12 force-email-change.png34.06 KBpiggito
#12 comment-edit-form.png33.88 KBpiggito
#7 edit-comment-2398073-7.patch741 bytesjespermb
#3 edit-comment-2398073-3.patch651 bytesjespermb
#2 drupal-remove_email_comment_access-2398073-2.patch819 bytespingers
Screenshot 2014-12-24 08.19.49.png38.72 KBlarowlan

Comments

larowlan’s picture

Issue tags: +Novice
pingers’s picture

Is this what you had in mind @larowlan?

jespermb’s picture

StatusFileSize
new651 bytes

Hi,

I also came up with a solution for this.

jespermb’s picture

Status: Active » Needs review

Changed status to need review.

The last submitted patch, 2: drupal-remove_email_comment_access-2398073-2.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 3: edit-comment-2398073-3.patch, failed testing.

jespermb’s picture

Status: Needs work » Needs review
StatusFileSize
new741 bytes

Reworked the patch a bit.

larowlan’s picture

Patch at #2 is the right approach thanks @pingers (and hi by the way - hope you'll be in Melbourne in March)

penyaskito’s picture

Why admins should not be able to edit?

larowlan’s picture

The should be able to edit for anonymous users, but not for authenticated users, the email there is a property of the user

piggito’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +LatinAmerica2015
StatusFileSize
new33.88 KB
new34.06 KB
new34.12 KB
new30.25 KB

Hi,

I used SimplyTest to test the patch at #7.

First, I created a Basic Page node with the admin user. Then, I created an "authenticated user" called "test". As the "test" user, I commented on the node. Then, I got into the comment edition form using the admin user as shown in the following screenshot.
Comment Edit Form

This screenshot depicts the email field disabled. Therefore, I tried to force an email variation by directly modifying the HTML (as shown in the next screenshot) but it wasn't modified in database after submit.

Forcing email change

Finally, I changed the author of the comment using the "Authored by" autocomplete field and the email did change this time to the email of the new author (shown in the following screenshots).

Author Change
Author and Email changed

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: edit-comment-2398073-7.patch, failed testing.

pingers’s picture

@piggito see comment #8. I don't think the patch you're testing is the right one. Thanks.

@larowlan I will indeed be in Melbourne :)

sidharrell’s picture

this is pinger's patch from #2. Just re-enqueueing it here at the top of the file list so it's clear which one to test with.
I applied it, went through the test steps, and the email field is gone, see screenshot.

sidharrell’s picture

Status: Needs work » Needs review
larsmw’s picture

StatusFileSize
new822 bytes

Would it make sense to disable the field, so the admin can still view the email of the user?

Status: Needs review » Needs work

The last submitted patch, 17: 2398073.patch, failed testing.

Swarnendu-Dutta’s picture

Status: Needs work » Needs review
StatusFileSize
new1.72 KB

Created a patch..please review..

Status: Needs review » Needs work
Swarnendu-Dutta’s picture

Status: Needs work » Needs review
StatusFileSize
new1.27 KB
pingers’s picture

If we disable email(#disabled) and still allow an administrator to change the comment owner, the email address does not change. You will see the previous comment owner's email address when editing the comment owner. This feels wrong to me. On these grounds, I think we should go with my original patch and hide the email address for authenticated comments (via #access).

Currently, the original commenter's email is still stored if you only change the user name (in comment_field_data.mail). But, at least if we hide the email from UI for authenticated comment, changing the owner of a comment makes sense in the UI.

@Swarnendu-Dutta

  1. +++ b/core/modules/comment/src/CommentForm.php
    @@ -149,6 +149,7 @@ public function form(array $form, FormStateInterface $form_state) {
    +      $form['author']['name']['#attributes']['disabled'] = TRUE;
    

    Using #attributes to disable a field means the value can still be updated via Javascript and will be saved. Should use Form API #disabled.

    Changing name is out of scope of this issue.

  2. +++ b/core/modules/comment/src/CommentForm.php
    @@ -171,6 +172,9 @@ public function form(array $form, FormStateInterface $form_state) {
    +      $form['author']['mail']['#attributes']['disabled'] = TRUE;
    

    This is wrong for the same reason as above, should use Form API #disabled.

    Also, disabling the email field for administrators under all conditions is wrong. We only want to prevent changing the email of comments owned by authenticated users.

Status: Needs review » Needs work

The last submitted patch, 21: comment-admin-sdnt-be-able-edit-email-2398073-21.patch, failed testing.

Swarnendu-Dutta’s picture

@pingers, So can we use readonly here ??? i know it can be exploited through firefug but atleast the admin wont be able to edit through the UI..

pingers’s picture

@Swarnendu-Dutta "Admin should not be able to edit email of authenticated commenters".

Read-only very much applies in this case... or not at all. This issue is creeping in scope and making a simple change complex.

Let's close it out... patch from comment 2 still stands in my mind. Just needs review.

Swarnendu-Dutta’s picture

Status: Needs work » Needs review
sidharrell’s picture

Status: Needs review » Reviewed & tested by the community

#2 looks good to me. Has passed all the manual testing I threw at it. Also seems to make the most sense UIX-wise. If the email field remains in the UI, it leads to a user expectation that it could be changed here. I don't think there's a good argument for leaving the field there as non-editible, since the author is still there, identified by username, adding a re-identification by email doesn't seem to add anything to the UI, and just clutters it unnecessarily, in my opinion.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

We should have a test for this and also if #2 is the patch to go for then is needs to be re-uploaded since the rtbc retest only tests the last patch on each issue.

Swarnendu-Dutta’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new819 bytes
new819 bytes

@alexpott,
Re-uploaded and setting this to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Still needs a test.

geertvd’s picture

The last submitted patch, 31: drupal-remove_email_comment_access-2398073-31-test.patch, failed testing.

mohit_aghera’s picture

Updated comment email field access settings based on settings specified in content type settings.

The last submitted patch, 33: drupal-remove_email_comment_access-2398073-32-test.patch, failed testing.

geertvd’s picture

Status: Needs review » Needs work

Thanks for adding that.

I guess we can just set that setting with $this->setCommentAnonymous('2'); since we really need that contact information for this test.

Then these lines can be removed:

+++ b/core/modules/comment/src/Tests/CommentAdminTest.php
@@ -168,4 +168,43 @@ class CommentAdminTest extends CommentTestBase {
+    $field_name = $comment->getFieldName();
+    $field_definition = $this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$comment->getFieldName()];
+    $anonymous_contact = $field_definition->getSetting('anonymous');
...
+    if($anonymous_contact == COMMENT_ANONYMOUS_MUST_CONTACT) {
...
+    }

Looks like you forgot to add the updated test in the complete patch also

sidharrell’s picture

Status: Needs work » Needs review
StatusFileSize
new2.5 KB
new787 bytes

added the updated test from #32 and the idea from #35.

Status: Needs review » Needs work

The last submitted patch, 36: admin_should_not_be-2398073-36.patch, failed testing.

mohit_aghera’s picture

I think
$this->setCommentAnonymous('2');
should be above
$anonymous_comment = $this->postComment($this->node, $this->randomMachineName());

geertvd’s picture

$this->setCommentAnonymous('2'); should be above $anonymous_comment = $this->postComment($this->node, $this->randomMachineName()); like #38 is saying.

+++ b/core/modules/comment/src/Tests/CommentAdminTest.php
@@ -168,4 +168,39 @@ public function testCommentAdmin() {
+    $entity = $this->entityManager->getStorage($comment->getCommentedEntityTypeId())->load($comment->getCommentedEntityId());

What's happening here? I don't see this variable being used anywhere.

Best to always add a failing test and the complete patch.

mohit_aghera’s picture

Updating the patch as per the comment and moving as per #38

mohit_aghera’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 40: drupal-remove_email_comment_access-2398073-40-complete.patch, failed testing.

The last submitted patch, 40: drupal-remove_email_comment_access-2398073-40-test.patch, failed testing.

mohit_aghera’s picture

Changing patch and adding admin login for setting comment anonymous setting.

mohit_aghera’s picture

Status: Needs work » Needs review

The last submitted patch, 44: drupal-remove_email_comment_access-2398073-41-test.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 44: drupal-remove_email_comment_access-2398073-41-complete.patch, failed testing.

geertvd’s picture

Just missed adding the contact info while posting the anonymous comment. This should fix it.

geertvd’s picture

Status: Needs work » Needs review

The last submitted patch, 48: drupal-remove_email_comment_access-2398073-48-test.patch, failed testing.

Thomas Willemsen’s picture

Status: Needs review » Reviewed & tested by the community

I followed the steps.
Looks good (e-mail of logged in user can't be changed by admin - for an anon user it still can be changed).

Bojhan’s picture

So there is no argumentation in this issue? Other than an opinion, that it shouldn't. Is it legally their property? Are people actually not allowed to do this?

larowlan’s picture

+1 rtbc, bohjan, this was a regression

sidharrell’s picture

+1 rtbc
@Bojhan the admin can change the author here, and they can go into the author's account and change the email address there. I think the point is you don't want the author's email editable here cause it makes it ambiguous. If you edit it here, is it editing it just here, or will that change also show in the author's account? From UIX, it's cleaner, with a single connection, comment-to-author(by name), rather than 2 redundant connections, comment-to-name and comment-to-email.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 5430ac9 and pushed to 8.0.x. Thanks!

  • alexpott committed 5430ac9 on 8.0.x
    Issue #2398073 by mohit_aghera, geertvd, sidharrell, Swarnendu-Dutta,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.