Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.11
Component:
user data
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
20 Jun 2010 at 17:26 UTC
Updated:
20 Apr 2012 at 11:51 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dawehnerThis sounds like a real critical bug for me. Can you export one of these views?
Comment #2
skyliner commentedAn export of View Block is included below - It presents a list of (non-Admin) usernames.
I hope this helps.
$view = new view;
$view->name = 'user_list';
$view->description = 'User List';
$view->tag = 'User List';
$view->view_php = '';
$view->base_table = 'users';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'uid' => array(
'label' => 'Uid',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_user' => 0,
'exclude' => 1,
'id' => 'uid',
'table' => 'users',
'field' => 'uid',
'override' => array(
'button' => 'Override',
),
'relationship' => 'none',
),
'name' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 1,
'path' => 'user_tracker/[uid]',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_user' => 0,
'overwrite_anonymous' => 0,
'anonymous_text' => '',
'exclude' => 0,
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
'override' => array(
'button' => 'Override',
),
),
));
$handler->override_option('sorts', array(
'name' => array(
'order' => 'ASC',
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'rid' => array(
'operator' => 'not',
'value' => array(
'4' => '4',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'rid',
'table' => 'users_roles',
'field' => 'rid',
'relationship' => 'none',
'reduce_duplicates' => 0,
),
'uid' => array(
'operator' => 'not in',
'value' => array(
'0' => 0,
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'uid',
'table' => 'users',
'field' => 'uid',
'relationship' => 'none',
),
'uid_current' => array(
'operator' => '=',
'value' => '0',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'uid_current',
'table' => 'users',
'field' => 'uid_current',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('title', 'Other Users');
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'grouping' => '',
'type' => 'ul',
));
$handler = $view->new_display('block', 'Other Users', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
Comment #3
dawehnerThanks
Comment #4
tdonia commentedI've encountered a similar issue that sounds related. here are the symptoms i've found:
1) most pages are fine/i'm not seeing any issues with disappearing blocks though my site doesn't use blocks heavily so that might not be meaningful
2) only 2 pages that list articles [standard default content-type] or events [cck content type] have problems
2b) all other content type views work as expected
3) on those problem content-type pages, the $user->roles array doesn't indicate the Role label; rather, the array is [autoincrementing key]=>[role id #] ( vs. the expected [role id #] => [role label]
4) on those problem pages, only admin users have permission to edit articles / are rendered the edit link
5) on the actual node edit page, a given role has no problems editing
for now i've had to revert to 2.10 which fixed the problem temporarily. if i find anything else related, i'll post.
Comment #5
skyliner commentedThanks tdonia, you encouraged me to dig through the configuration of the views and blocks in relation to Roles...
I have discovered that Views Blocks disappear when you set the Block to 'only' appear for a selected Role(s), e.g. Authenticated User etc, even when you are within that Role.
Likewise, if a Menu Block can be seen by all Roles, but it links to a View which is accessible only by certain Roles, then the Menu Block disappears.
Glad to be able to isolate the issue, but don't think I can work around it, so am keener than ever for a fix.
Comment #6
SebCorbin commentedWow wow wow ! This bug is currently breaking my site : when I do a global $user; I find the exact description of tdonia's problem
An array of autoincremented keys with $rid as values, problem is : it change the global $user object, and when I'm doing tests later in code with isset($user->roles[$rid]), it doesn't work.
This breaks my site since Sunday. So yes, this is critical. I'm digging into the code right now to find the problem...
I've found this issue searching for $user->roles on Views project because I notices a line in last Changelog :
#815392 by killes and dereine: Incorrect construction of $account caused accidental non-permanent change to $user->roles.
Comment #7
dawehnerHere is a patch
Comment #8
tdonia commentedThanks! the patch seems to solve it for me. I'll post back here if i encounter any related issues but so far all testing is positive.
Much appreciated.
Comment #9
tdonia commentedActually - sorry to be a bother, it's possible this is my own operator error, but the patch seems to be for the version of views_plugin_argument_validate_user.inc that's part of 3.x-dev - is that OK / are those files interchangeable?
Comment #10
tdonia commentedAnd now i'm noticing a new issue in the patched version - views are only showing content that's been created by the user that's viewing. Sorry for not catching that sooner. Seems to happen whether i (manually) apply the patch to 2.11 views_plugin_argument_validate_user or to the 3.x dev version. Will poke around and see if i can come up with any leads.
Comment #11
dawehnerI really wonders how this worked. Roles has the same structure as $user->roles on a normal drupal.
Comment #12
dawehner@tdonia
What do you think this argument validation does? It gives/denies you access to views, if the argument is
a) the current user
b) one of role X
Comment #13
tdonia commentedGood tip. If this returns false, per my view definitions, it'll display all results. If this returns true, it should only display the results that are allowed for the given user. That's sort of backwards from a design perspective, but the intended use here is 'if we know this person is a reporter, they should only see their own work; if we know they're an editor or admin, they can see everything'. What's still throwing me is that admin/editors are now being limited to only what they've created. Maybe it's possible that we've been relying on a bug and should just redesign our views? It's hard for me to judge what the 'correct' behavior here is supposed to be.
Comment #14
dawehnerThis is really something rather totally different
"if we know this person is a reporter, they should only see their own work;"
Then you would have to add a filter user: current
It seams that you want to have different views for different users
Comment #15
waldmanm commented@dereine - thanks for the patch. I can confirm that it is working and has solved the problem I had after upgrading to 2.11 where a first use of a view would bring results but subsequent uses would return nothing (because the global user account roles were modified improperly).
That said, I believe the code path in my case is using the global user account, so I haven't tested your code to add the roles to a new local $account. From looking at the code it seems it should work (at least it's much better than the original :).
Comment #16
merlinofchaos commentedarray_intersect_key() is PHP 5.1+ only -- we can't use that function as we need to retain PHP4 compatibility.
Comment #17
Mark Theunissen commentedHere's another approach.
1. We already have the roles in the global $user object, so don't requery in that case.
2. Use array_intersect() as before on two arrays with role ids as their values.
3. More explicit variable naming.
Comment #18
Mark Theunissen commentedComment #19
dawehnerLooks fine.
I didn't tested the patch yet.
Comment #20
skyliner commentedThanks Mark, just tested the patch and it's definitely fixed my original issues. Nice one.
Comment #21
dawehnerSo
Comment #22
dawehnerRename the title to be able to find it
Comment #23
ezra-g commentedThis patch resolved the incorrect formatting of $user->roles for me. Thanks, @Mark Theunissen.
Comment #24
stephthegeek commentedYeeeah this was kind of a headache, but fixed by the patch. Thanks!
Comment #25
tinkerbelle commentedOh, neat: this patch solves a problem I had with Better Formats and FCKeditor not respecting role settings, which I had initially traced only as far back as Project issue tracking (#859048: function project_issue_views_user_access breaks FCKeditor and default input formats.).
I hate to run a patched module on my production site though. I guess there's no way of knowing how soon a bugfix like this will make it into an official release?
Comment #26
pieterdcPatch from comment #17 solved my problem. Thanks Mark Theunissen.
Comment #27
cyberwolf commentedQuite critical issue, subscribing.
Comment #28
BiiigP commentedI have simular problem as in post #25
However i have no idea how i have to apply this patch? Can i do this manualy?
Comment #29
dawehnerhttp://drupal.org/patch/apply is the tutorial how to apply patches. I would never suggest to do this manually, because this can cause many problems.
Comment #30
ezra-g commentedIs there anything specifically preventing this patch from being committed?
Comment #31
merlinofchaos commentedYes, it appears that it applies to 2.x but not 3.x. Can I get a reroll for 3.x (and preferably 7.x-3.x as well?)
Comment #32
dawehnerhere are some reroles
Comment #33
dwwI think these patches are the wrong approach. This argument validator shouldn't be touching the global $user object at all. And, if it weren't for PHP being evil, we wouldn't be. The root of the problem is here:
$account = $GLOBALS['user'];
If $GLOBALS['user'] were an int, this would do what we think it does -- you just get a copy (not a reference) to the int. For example:
This gives you the following output, as you'd expect:
However, if you try it with an object:
You get this:
Argh. Thanks, PHP.
We don't want to be touching $GLOBALS['user'] here and modifying anything. I think a well-placed drupal_clone() will solve this much cleaner and safer. Stay tuned...
I'd normally consider a bug like this something to solve via the security team process. However, it doesn't appear that this bug can lead to elevated privs, so I guess we can continue to solve it here in public...
Comment #34
dwwUntested. Rolled for D6--2 branch, although it applies (with minor fuzz) to both D6--3 and D7--3.
Comment #35
dwwNote: I tested this. It does continue to work, and it solves the bug. I'm planning to just commit to all 3 branches later today unless there's a serious objection.
Comment #36
dawehnerLet's get it fixed. This patch fix the issue and looks fine and explains the problem very well.
We talked a bit in IRC so we should try to clean up the plugin in another issue.
Comment #37
dwwThanks for the review! Committed to:
DRUPAL-7--3
DRUPAL-6--3
DRUPAL-6--2
Comment #38
dawehnerIN d7 drupal_clone does not exist anymore. I commited a fix in the current CVS.
Comment #39
dwwThanks dereine: I should have tested more carefully before committing!
Comment #40
dawehnerHey, i set the patch as RTBC. This happens.
Comment #41
amitaibu@dww,
A question - it's a common thing to see in drupal:
Does it mean, according to your findings, that the correct line should be
$account = clone($user);?Comment #42
dww@Amitaibu: Yeah, a little further investigation says "yes". You need to clone($user) when you assign it to $account, or changes to $account will change the global $user. *sigh* We (the security team) should blog about this. I know we've been suggesting to use $account like this in the past, we should clarify.
Comment #44
fonant commentedPhew, this is a nasty one. Caused all sorts of problems with Content Access and nodereference on a site I'm building. The nodereference field was testing for permissions to view the referenced node using the $user->roles array that had been mangled by Views. So rather than using the actual role IDs it was using role IDs counting up from zero: i.e. anonymous and authenticated rather than the actual roles of the current user. So permission was denied when it shouldn't have been, resulting in "this post can't be referenced" even when the autocomplete field had found the node in question!
Comment #45
fonant commentedIt could possibly result in elevated privileges, as the current user's role IDs are reduced from high numbers to a series of numbers starting from zero. So in this, probably fairly unusual situation, we could have problems:
rid 0 = anonymous
rid 1 = authenticated
rid 2 = site administrator (a high-privilege role with a low role ID value)
rid 3 = normal user (a low-privilege role)
rid 4 = other user (a second low-privilege role)
Demo user before roles get messed up:
$user->roles = array(1 => 'authenticated', 3 => 'normal user', 4 => 'other user');
And after:
$user->roles = array(0 => 1, 1 => 3, 2 => 4); // effective roles 'anonymous', 'authenticated', 'site administrator'.
i.e. a user could gain low-numbered roles that they aren't supposed to have, if they have more than two roles assigned to them.
In any case this causes problems as registered users will end up with both anonymous and authenticated roles. Not nice.
Comment #46
NaX commentedI have also just waisted lot of time with this issue which also caused elevated privileges on one of my sites. The most frustrating for my users was menu items appearing in the primary links they don't have access to. At least when they tried to access the link they got an access denied page.
When you combine this issue with panels things can get even more scary.
I would like to suggest a new release of views because of this issue as it is a security risk.
Comment #47
dwwThis bug is fixed. Please open a new issue (and link to this one) if you want to advocate for a new official views release. Simply re-opening this issue isn't going to help. Thanks.
Comment #48
tinkerbelle commentedThis fix doesn't seem to have made it into today's 6.x-2.12. Can anyone clarify for me what is meant by "fixed", if it's not at least "will be included in the next release"?
Comment #49
dww@tinkerbelle: 6.x-2.12 was a security-only bug fix, created from the 6.x-2.11 codebase with only a single patch applied (to fix a security vulnerability). All of this you would know if you read the 6.x-2.12 release notes. So yeah, normally, "fixed" means "will be available in the next release. However, security releases are a special case, so this bug fix will be included in the 6.x-2.13 release. Such is life.
Comment #50
BiiigP commentedThe bug gave problems using IMCE (with wysiwyg en imce_bridge) after applying the security update. I just used the patch again and that did work.
Comment #51
tajindersingh commentedThanks for the patch.. helped but wasted whole one day digging and blaming Panels module.
Must be in the 6.x-2.12 as update, might have saved good time.
Thanks again :)
Comment #52
abaddon commentedi think this could create a security issue if the original user has a number of roles assigned >= 4, the modified object will have the number of those roles assigned as keys (0=>, 1=>, 2=>, 3=>..)<-user with 4 roles.., which grants the user access to your first custom created role, this could be a super admin account.. user_access only checks keys so the values are not important
if the view runs on a page where that user could benefit access, then he will
i didnt test this, but if im right, it should go through the security team.. ill make a note of this there before opening the issue again
Comment #53
fuzzy76 commented