Remove CSRF vulnerability from comment module

GiorgosK - May 30, 2006 - 12:10
Project:Drupal
Version:7.x-dev
Component:comment.module
Category:bug report
Priority:critical
Assigned:boombatower
Status:needs work
Description

could be offered as a link where the comment is displayed (next to the "delete edit reply" links)

Normally one has to see the content of the comment in order to approve it so one has to edit it first and then check publish and then save the comment. It would be very convenient to have an "approve" link next to the "delete edit reply" links for fast approval.

Sorry if Project and Component are not the appropriate ones.

#1

elv - October 24, 2007 - 10:47
Project:User experience» Drupal
Version:<none>» 7.x-dev
Component:usability» comment.module

This feature request is still valid in Drupal 6 beta2. To approve an individual comment you still have to click the "Edit" link, then click on the "Administration" fieldset title to open it, click the "Published" radio button, then scroll to the bottom of the page and click the "Submit" button. Phew!

So a one-click approval link would really be handy, if it's possible.

Redirecting to the comment.module issue queue. I guess this is for 7.x-dev because of the code freeze?

#2

boombatower - May 24, 2008 - 17:33
Assigned to:Anonymous» boombatower
Status:active» needs review

After using my Drupal blog I have noticed that this is a feature that would be very useful. I searched and found this issue so I have attached a patch to it rather than starting a new issue.

This is my first patch related to the comment module. It may be a bit rough around the edges.

AttachmentSizeStatusTest resultOperations
comment_approval.patch2.25 KBIdleFailed: Invalid PHP syntax.View details | Re-test

#3

boombatower - May 24, 2008 - 17:35
Title:comment approval» Comment approval displayed on node view of comment

#4

boombatower - May 28, 2008 - 16:49

Advised by chx to use comment_load.

AttachmentSizeStatusTest resultOperations
comment_approval.patch2.05 KBIdleFailed: Failed to apply patch.View details | Re-test

#5

boombatower - May 29, 2008 - 00:20
Status:needs review» reviewed & tested by the community

chx reviewed in IRC.

This includes a modified test to take this into account.

AttachmentSizeStatusTest resultOperations
comment_approval.patch4.78 KBIdleFailed: Failed to apply patch.View details | Re-test

#6

Dries - June 3, 2008 - 16:30
Status:reviewed & tested by the community» fixed

Excellent patch. With tests and everything. :-)

#7

sun - June 4, 2008 - 04:03

Great stuff!

+  $items['comment/approve'] = array(
+    'title' => 'Approve to comment',

sounds strange, like granting a permission to a user. Isn't it 'Approve a comment' ?

#8

boombatower - June 4, 2008 - 05:21
Status:fixed» reviewed & tested by the community

Yes, I think I was trying to write "the."

AttachmentSizeStatusTest resultOperations
comment_approval_menu_title.patch657 bytesIdleFailed: Failed to apply patch.View details | Re-test

#9

catch - August 14, 2008 - 16:21

still applies with offset.

#10

Dries - August 14, 2008 - 19:47
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Marking fixed ... thanks.

#11

cwgordon7 - August 16, 2008 - 04:05
Title:Comment approval displayed on node view of comment» Remove CSRF vulnerability from comment module
Category:feature request» bug report
Priority:normal» critical
Status:fixed» active

Sorry, this is a CSRF vulnerability. Either we need a confirm form or some sort of cron_key-like mechanism to allow this sort of one-click convenience to work without opening a security hole.

#12

boombatower - August 16, 2008 - 20:22
Status:active» postponed (maintainer needs more info)

Not following you.

Need to be logged in with correct privileges:

<?php
$items
['comment/approve'] = array(
   
'title' => 'Approve a comment',
   
'page callback' => 'comment_approve',
   
'page arguments' => array(2),
   
'access arguments' => array('administer comments'),
   
'type' => MENU_CALLBACK,
  );
?>

And link won't even be displayed unless you can administer comments anyway as they are considered unpublished.

If anything now that I look at it should the url be 'comment/approve/%' ?

#13

cwgordon7 - August 17, 2008 - 03:58
Status:postponed (maintainer needs more info)» active

#12 - @see http://en.wikipedia.org/wiki/CSRF please. No actions should ever be taken through an insecure GET request.

#14

boombatower - August 21, 2008 - 01:01

Believe I have it working, but I have to leave so post later.

#15

boombatower - August 21, 2008 - 04:16
Status:active» needs review

This should do it.

Updated test so that it take the confirmation form into account and it passes. Had 1 fail (as it should) before.

AttachmentSizeStatusTest resultOperations
comment_approval.patch3.39 KBIdleFailed: Failed to apply patch.View details | Re-test

#16

cwgordon7 - August 21, 2008 - 04:20

Why not use %comment instead of just %? Then you get comment_load() called automatically.

#17

boombatower - August 21, 2008 - 04:24

Sure, never used it before. Was just adding % so that it would be consistent and wouldn't allow comment/approve to be called.

Patch includes minor change.

AttachmentSizeStatusTest resultOperations
comment_approval.patch3.43 KBIdleFailed: Failed to apply patch.View details | Re-test

#18

boombatower - August 29, 2008 - 21:32

Still applies, ping.

#19

Damien Tournoud - August 29, 2008 - 22:01
Status:needs review» needs work

The patch looks good, except that these lines are completely unneeded, because confirm_form() has already set $form['#redirect']:

<?php
$comment = comment_load($form_state['values']['cid']);
$form_state['redirect'] = "node/$comment->nid";
?>

#20

boombatower - August 30, 2008 - 23:34

Checked into, but that doesn't seem to be the case.

* @param $path
*   The page to go to if the user denies the action.
*   Can be either a drupal path, or an array with the keys 'path', 'query', 'fragment'.

And it never sets #redirect, as it also doesn't work if I remove the lines in question.

#21

boombatower - August 30, 2008 - 23:35
Status:needs work» needs review

Patch still applies and ran comment test which returned all passes.

#22

System Message - November 16, 2008 - 21:45
Status:needs review» needs work

The last submitted patch failed testing.

#23

boombatower - November 16, 2008 - 23:47
Status:needs work» needs review

Re-rolled, DB TNG was the cause of failed to apply.

AttachmentSizeStatusTest resultOperations
comment_approval.patch3.59 KBIdlePassed: 8996 passes, 0 fails, 0 exceptionsView details | Re-test

#24

catch - November 19, 2008 - 15:10
Status:needs review» needs work

"You can unpublish comment" should be "You can unpublish this comment". Otherwise this looks good - except I'd rather see us use tokenised links to avoid CRSF for one click operations rather than confirm forms. That probably needs centralising though.

#25

boombatower - November 20, 2008 - 01:53
Status:needs work» needs review

Addressed #24.

AttachmentSizeStatusTest resultOperations
comment_approval.patch3.59 KBIdlePassed: 8993 passes, 0 fails, 0 exceptionsView details | Re-test

#26

sun - December 4, 2008 - 01:57

Sending for re-test.

AttachmentSizeStatusTest resultOperations
comment_approval_5.patch3.59 KBIdleFailed: 9021 passes, 3 fails, 3 exceptionsView details | Re-test

#27

catch - January 17, 2009 - 20:50

Why:

+  else {
+    drupal_set_message(t('The comment you are approving does not exist.'), 'error');
+    drupal_goto();
+  }

and not a 404?

Otherwise looks good.

#28

System Message - January 22, 2009 - 03:50
Status:needs review» needs work

The last submitted patch failed testing.

#29

David_Rothstein - November 9, 2009 - 04:07

@webchick rediscovered the CSRF vulnerability in #606608: Use proper menu router paths for comment/*. We should probably consolidate efforts here, but note there is a more up-to-date patch at http://drupal.org/node/606608#comment-2240294

She also pointed out that the access callback for this link is not correct (you should not be able to approve a comment that is already approved).

I also agree with @catch - it seems like the entire reason this was introduced was to have a convenient one-click approve link, so adding a confirmation form hurts that experience. We don't really need a confirmation form, just a token. Seems like we could get away without centralizing it - this isn't that common of link that people will be generating outside of a few special modules, and it's not hard for them to use the same token generation code as the comment module would use (and they'd learn to do that pretty quickly, since if they didn't, their links wouldn't work :)

 
 

Drupal is a registered trademark of Dries Buytaert.