I use the flag module and I have a security problem with a build-in view. I have submitted this issue to the Flag project, but they do not have a solution.

The view with the path "user/%/favorites" adds a tab to the user's account page and shows the "favorite" flagged nodes.
But if this user enters another argument in the url, he is able to see the favorites of other users.

Can this be solved by entering a php validation to the uid argument? If yes, what php code should I enter?

Thx.

Comments

tomsm’s picture

Category: support » feature

I would like to change this into a feature request: "Validate user argument is current user", as mentioned in this issue with the Flag project: http://drupal.org/node/596594

RoboPhred’s picture

For consistancy, the argument should probably be "Current user or admin", and also give access if the user has "Administrate users" or similar permission.

tomsm’s picture

@ RoboPhred

That's a good idea.

heather’s picture

Component: Documentation » user data

This is not a documentation issue. Just tidying up.

This may be a User data issue. Noted on Obtaining support for Views issues http://drupal.org/node/571990

404’s picture

subscribe

ericduran’s picture

Status: Active » Fixed

This can be accomplish by adding a "User: Current" filter to the views.

Feel free to change it back to active if I am wrong.

tomsm’s picture

Status: Fixed » Active

That is true, when I use this filter I cannot see the flagged content of other users.

But I can see the username that corresponds to the uid.
I get for example:

some_user's favorites

This user has not yet bookmarked any content.

So by changing the argument (=uid), I get information about the username and that is something I want to avoid for privacy and security reasons.

ericduran’s picture

Status: Active » Needs work
StatusFileSize
new1.85 KB

This patch add an "Only allow current user or admin" checkbox to the user validator.

I ran some test and nothing seem to had broken with the patch.

I'm no views expert so someone could probably implement it better.

All comments welcome.

merlinofchaos’s picture

Status: Needs work » Needs review

needs review is more likely to get attention =)

dawehner’s picture

Status: Needs review » Needs work
+++ modules/user/views_plugin_argument_validate_user.inc	25 Apr 2010 22:49:20 -0000
@@ -99,6 +106,15 @@ class views_plugin_argument_validate_use
+      if(!user_access('administer users', $GLOBALS['user'])){

we don't have to use globals here.

Powered by Dreditor.

ericduran’s picture

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

Here's an updated patch not using Globals.
Thanks for that.

rburgundy’s picture

Hi,

Just grammar-wise:

+    //Check if only the current user or admin is allow

should be

+    //Check if only the current user or admin is allowed
dawehner’s picture

Status: Needs review » Needs work

so

mparker17’s picture

Subscribe

dawehner’s picture

should be

+    // Check if only the current user or admin is allowed.

:)

dawehner’s picture

+    if (!empty($this->options['restrict_user'])) {
+      if (!user_access('administer users', $account)) {
+        if ($argument != $account->name && $argument != $account->uid) {
+          return FALSE;
+        }
+      }
+    }
+

We could save here also at last one or two if's

robby.smith’s picture

subscribing

lgb’s picture

subscribe

ericduran’s picture

lol, so I actually don't like this patch. Do we really want to hard code the settings to the 'administer users' permission. Wouldn't we want to make it a little more flexible than that?

dagmar’s picture

Status: Needs work » Needs review
StatusFileSize
new2.63 KB

I agree with @ericduran, 'administer users' is really a harmful perm. This patch allow to configure which permission is necessary if argument is not the current user.

merlinofchaos’s picture

Status: Needs review » Needs work

Role checking is a lot easier than permission checking, so I'd rather not go that route.

Also, this patch would simplify this a lot: http://drupal.org/node/644008 -- the use of actual permissions rather than validation.

dunx’s picture

This is quite an old thread, but I have exactly the same issue as the OP.

I can't see that this patch has been applied and I can't find a suitable solution via Views alone, so I thought I'd post something here in case there is an alternative solution these days and I've missed something.

Basically, Views view Access based on whether the user argument passed in is the current user (or the current user is admin). I don't want any old user able to view other user's Bookmarks.

mustanggb’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)