Problem/Motivation

There is some inconsistency on how we show links on hook_permission functions. On some places we use user_access on the menu to make sure the user can access the link, on some places we don't. Specifically, such a call was removed from filter_permission as documented on this issue: https://drupal.org/node/1684930.

Proposed resolution

We can either add that check to such functions, like the check that was removed from filter_permission. The fear is that it doesn't feel right to do a user check on a hook info function that is defining the permissions. As mentioned by @dawehner (in [this comment](https://drupal.org/node/1684930#comment-6905328)) user_access does not call hook_permission, but doing a check does block it from being cached for every user. Right now seems like hook_permission is not bein cached. The other places where I could find links that used a user_access call in the hook_permission function where file and node modules:

git grep -A 40 'hook_perm' | grep user_access
core/modules/file/file.module-      'description' => user_access('access files overview')
core/modules/node/node.module-      'description' => user_access('access content overview')

Remaining tasks

Either remove user_access calls from file and node hook_permission modules, or add it back to filter_permission and look for other possible candidates.

I would vouch for removing it for consistency.

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

g3r4’s picture

Assigned: Unassigned » g3r4

I'll work on a patch to solve this issue

g3r4’s picture

I removed the calls to user_access on the file.module and the node.module files, sending patch for testing and discussion

g3r4’s picture

Status: Active » Needs review
joshi.rohit100’s picture

for consistency, changed '@url' to '!url'
Please review now.

g3r4’s picture

_

amitgoyal’s picture

url() has been replaced with \Drupal:url() as per D8 standard.

As there is no routing info available for admin/content/files so that has not been updated in file.module.

jackbravo’s picture

Status: Needs review » Reviewed & tested by the community

The patch works ok for me, and it is pretty easy and straightforward. Marking as RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: remove-user_access-on-hook_permission-2283717-6.patch, failed testing.

joshi.rohit100’s picture

Status: Needs work » Needs review

status change

jackbravo’s picture

Status: Needs review » Reviewed & tested by the community
chx’s picture

I looked at this patch and do not readily see any security implications despite the very scary title :)

David_Rothstein’s picture

Fixing the inconsistency in this direction is fixing a bug that doesn't exist ("uncacheability" of something that's never cached, and probably doesn't have much reason to ever want to cache?)... and in exchange it introduces an actual user-facing bug: more 403 errors for users following links in the admin interface.

Fixing it the other way removes the existing 403 errors, in exchange for some code complexity.

But it's rare for an admin to be able to see the permission page and not see these other pages, and also there are probably plenty of other similar 403 errors elsewhere in the admin interface (links in help text?), so just saying we're going to consistently show them the link in these situations regardless of whether they can access it is probably not so terrible.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Also an admin knowing that there is functionality they don't have permission to access is useful information.

Committed 3e34d84 and pushed to 8.x. Thanks!

  • alexpott committed 3e34d84 on 8.x
    Issue #2283717 by amitgoyal, joshi.rohit100, g3r4 | jackbravo: Remove...
David_Rothstein’s picture

Version: 8.x-dev » 7.x-dev
Status: Fixed » Patch (to be ported)

As discussed in #1684930: Add description to "administer filters" permission this could perhaps be backported (or at least it could be discussed)? It wouldn't break any translations, since it would just remove some translatable strings.

I'm not sure Drupal 7 actually has an inconsistency currently though (everything I saw, at least on a standard install, does check the permissions). Also, it just occurred to me that to the extent that contrib modules are following core's pattern, we might not want to change it out from underneath them...

er.pushpinderrana’s picture

Status: Patch (to be ported) » Needs review

@David_Rothstein, I have removed user_access() from node_permission function in node.module but in file.module there is no hook_permission found.

Please review attached patch for D7.

er.pushpinderrana’s picture

Sorry forget to attach patch. Here is patch.

David_Rothstein’s picture

Status: Needs review » Needs work

That looks right to me.. but I know there's (at least) one more place in the D7 codebase where user_access() is used in hook_permission(): the Filter module (since that's what kicked off this issue in the first place).

joshi.rohit100’s picture

Status: Needs work » Needs review
FileSize
1.67 KB

updated the patch with user_access() remove from hook_permission() in filter module.

amontero’s picture

Assigned: g3r4 » Unassigned
Status: Needs review » Reviewed & tested by the community

Patch review:

  • Applies cleanly against 7.x
  • Created a 'test' user with only 'Administer permissions' perm.
  • Created a 'test' text format with no roles having access granted to it.
  • Same links are visible at permissions page both for uid 1 and 'test' user.
  • Checked with user 1 that all pages linked there are accessible.
  • Checked with 'test' user that 'Access denied' is returned when following the same links, as expected.

Patch is OK.

Notice: linked below there is a postponed issue awaiting to completion of this one.
#1684930: Add description to "administer filters" permission

Status: Reviewed & tested by the community » Needs work

Status: Needs work » Needs review
David_Rothstein’s picture

Status: Needs review » Reviewed & tested by the community

Testbot fluke.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +7.36 release notes

OK, it sounds like this is the direction people want to go in, so let's do this.

I enabled all core modules and looked at the Permissions page and didn't see any others that had links with a permission check on them, so this looks good.

Committed to 7.x - thanks!

Made this fix on commit, since the code comment was no longer correct:

--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -348,8 +348,6 @@ function filter_permission() {
   foreach (filter_formats() as $format) {
     $permission = filter_permission_name($format);
     if (!empty($permission)) {
-      // Only link to the text format configuration page if the user who is
-      // viewing this will have access to that page.
       $format_name_replacement = l($format->name, 'admin/config/content/formats/' . $format->format);
       $perms[$permission] = array(
         'title' => t("Use the !text_format text format", array('!text_format' => $format_name_replacement,)),

  • David_Rothstein committed e8a38c6 on 7.x
    Issue #2283717 by joshi.rohit100, amitgoyal, g3r4, er.pushpinderrana:...

Status: Fixed » Closed (fixed)

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

kenorb’s picture