I noticed that in node_content_access(), the $account parameter is not passed through to user_access() when delete permissions are being checked (but it is passed through when "edit" and "create" permissions are checked). I'm not entirely sure what the consequences of this would be, but it seems like a bug, so a patch is attached.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

FileSize
757 bytes

Here's the patch.

David_Rothstein’s picture

Status: Needs review » Needs work

Actually, there's some more confusion here (either in my head or in the function; apologies if the former). It seems like parts of this function use the global $user variable and parts use the passed-in $account. I would think that $user should only be used when $account is not passed in.

David_Rothstein’s picture

Title: check for delete permissions does not pass through $account » Core modules implement hook_access incorrectly
Priority: Normal » Critical
Status: Needs work » Needs review
FileSize
3.04 KB

OK, it turns out that there is a wider problem. Many of the core modules do not implement hook_access() correctly. In particular, when a user $account is passed in, they will occasionally ignore it and do permission checks against the global $user account (i.e., the currently logged-in user) instead.

I think this patch should take care of it -- it removes all references to the global $user account from the offending functions and instead forces them to use the passed-in $account parameter. (One reason for the problem might be that the documentation for hook_access at http://api.drupal.org/api/function/hook_access/6 is not up to date; it does not reference the $account parameter which is now passed in when this hook is called).

I am marking this as "critical" since doing permission checks against a different user than the one which was requested is obviously a potential security flaw. However, I'm not sure how critical it is in practice, given the way hook_access is called from within Drupal core... but either way, it should be fixed. Thanks.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

i reviewed and tested this. looks good.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Reviewed. Looks good, committed, thanks.

Gábor Hojtsy’s picture

You can update the hook_access() docs in contributions/docs. Please do so.

David_Rothstein’s picture

I don't have a CVS account, so I posted a patch to update the hook_access() docs here: http://drupal.org/node/206401

Anonymous’s picture

Status: Fixed » Closed (fixed)

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