Administrator user gets 'Access denied' when trying to edit/update menu link that points to '/user/login' URL.
Steps to reproduce:
* As an admin, Create a custom menu link with the "/user/login" for the link field
* Edit the menu link to change its link value to another but an access denied message "You are not authorized to access this page" is shown instead
Expected behaviour:
An admin user could access and change a menu link with value "/user/login" to another one.
| Comment | File | Size | Author |
|---|---|---|---|
| #58 | 2492513-58.patch | 3.53 KB | jofitz |
| #58 | interdiff-57-58.txt | 591 bytes | jofitz |
| #57 | 2492513-57.patch | 3.52 KB | gaurav.kapoor |
| #53 | After applying patch - change the menu link and save.jpg | 84.86 KB | NikitaJain |
| #53 | After applying patch - Edit login menu link.jpg | 83.67 KB | NikitaJain |
Comments
Comment #1
rajeev h commentedComment #2
rajeev h commentedComment #3
rajeev h commentedComment #4
alx_benjamin commentedHere is a patch, let's see if it will fail any or all tests.
I removed access check for internal links. As far as I can see it doesn't need to be there.
Please correct me if I am wrong.
-------------------------------------------------
Sponsored by http://reallifedesign.co.uk/
Comment #5
alx_benjamin commentedComment #6
NikitaJain commentedTested the above patch menu-link-edit-access-2492513-1.patch. Its working fine. Manually verified admin user can access and edit the menu link with value "/user/login" to another one after applying the patch.
1. Patch applied successfully without errors.
2. Tested on Firefox & chrome browser (Ubuntu 14.04)
2. Added a link 'User Menu' http://localhost/drupal/admin/structure/menu/manage/account/add
3. Before applying patch: On click to edit link, giving an error "You are not authorized to access this page" as an admin user.
4. After applying patch: On click to edit link redirects the user to this url http://localhost/drupal/admin/structure/menu/item/4/edit?destination=/dr...
Result: Issue is resolved after applying the patch. Admin user can able to access and change the menu link.
Screenshot attached.
Comment #7
dawehnerWe need tests but we also need to come up with a proper solution. Removing any acces checking is here is IMHO not the right solution
Comment #8
rashidkhan commentedHere is a patch attached. This patch doesn't remove the access check, instead it checks if access for the current user to the given link is forbidden or allowed.
Comment #9
rashidkhan commentedComment #10
rashidkhan commentedComment #11
dawehner.
Comment #12
NikitaJain commentedTested again the recent patch fixed-edit-menu-link-as-admin-2492513-8.patch. Its working fine. https://www.drupal.org/node/2492513#comment-10368139
Comment #14
shabbir commentedHi,
I have tested the issue on my side and found that the issue is with _user_is_logged_in validation. I changed the permission in user.routing.yml _user_is_logged_in: 'FALSE' to _user_is_logged_in: 'TRUE', cleared cache and then tried to edit the link and it worked. I reckon the issue is drupal is checking /user/login to be allowed for anonymous user, in our case when we try to edit the link, the drupal behavior is checking the user_logged_in permission and thus giving us 'Access Denied'.
Comment #15
nitesh pawar commentedHope this will works.
Comment #16
shabbir commented@nitesh: it works perfectly with edit link, the issue is when a non admin user with administer menu permission creates a menu and enters /user/login as link the issue still prevails.
Comment #17
shabbir commentedComment #18
nitesh pawar commented@shabbir, please check "link to any page" permission.
Comment #19
shabbir commented@nitesh: tested with "link to any page" permission for user with "administer menu" role and applied your patch, it works fine. For admin user i didn't gave "link to any page" permission and it worked as well. Works fine. Please someone else review and give your comment as well.
Comment #20
ameymudras commentedComment #21
alexpottStill needs tests.
Comment #24
esolitosThis seems very much related to #2409099: Edit access to custom menu links not granted to users with "link to any page" permission
Comment #25
jeroentAdded a test.
Comment #26
nikhilsukul commentedHi @JeroenT,
Just checked the patch in Drupal Version 8.2.3.
It works fine.
Comment #28
jeroentComment #29
pierremarcel commentedI also applied the patch and it's working, so far so good, I'm building a new site so I'll report back if I find any issue. For those that would like to help test this patch and are not sure how, just download the patch add to menu_link_content module and via command line ```git apply --stat cannot_edit_the-2492513-25.patch```
Thanks @jJeroenT for the patch!
Comment #30
jeroent@nikhilsukul or @PierreMarcel,
Thanks for the reviews. If any of you could RTBC this issue, that would be great.
Comment #31
nikhilsukul commentedComment #32
xjmThanks for working on this!
Two minor things to fix with this comment:
I'd say: "Tests the 'link to any page' permission for a restricted page."
Comment #33
xjmWe could also add an inline comment above these lines that says "The user should be able to edit a menu link to the page, even though the user cannot access the page itself." That makes up for having less information in the method docblock, I think.
Comment #34
keshavv commentedHere is a patch for drupal 8.2.x
Working fine for me .
Comment #35
jeroentMade changes as suggested in #32 and #33.
Comment #36
amit.drupal commentedPatch #35 is working beautifully . Thanks for patch.
Comment #37
pierremarcel commentedTested and working great! Changing it to RTBC, also changed the priority to Major, just because I'm thinking about new people trying Drupal it would be common to add login path to a menu, and I would hate to hear bashing us just because a silly bug like this.
Great Job @JeroenT thanks!!!
Comment #38
xjmThanks everyone!
This does not meet the criteria for a major bug, so marking back to normal priority.
I just noticed that we also need to update this comment to reflect the change. Sorry for not catching this on the first review! However, I think we can make it even clearer. Comparing this to the the alternate fix proposed in #34, in both cases, it is actually a little confusing. Instead of either approach, I think we should add an explicit case to return earlier if the account has the permission, because if we do have the permission, we don't need to do any of this either:
It's interesting that the check for this permission was overlooked, especially since numerous other places in core do check this permission:
I used
git log -Land the two issues (other than for cacheability improvements) are #2340507: Make the new AccessResult API and implementation even better and the original #2301239: MenuLinkNG part1 (no UI or conversions): plugins (static + MenuLinkContent) + MenuLinkManager + MenuTreeStorage. There are no other references to this permission in that issue either. Since there are three different ways to define menu links, we should probably make sure that all three respect this permission. The fact that we need to check it so many times in so many different places also makes me wonder if the access check should be provided for menu links at a higher level.Based on all that, I think it would also be good to get a menu subsystem maintainer review.
I tagged the issue for subsystem maintainer review, but in the meantime, we can still update the patch for point 1. Thanks!
Comment #39
jeroentOk if I change the comment in #38.1 to
We allow access when the link is accessible or the user has the 'link to any page' permission.?Comment #41
jeroentComment #42
jeroentMarking as RTBC since there are only comment changes.
Comment #43
alexpottThere's no need to check link access if the account has the 'link to any page' permission so this can be rewritten as:
Plus lets fix the comment on the first line since this part of the if is not dealing with external links only.
Assume that access is allowed.is an acceptable replacement. And the comment that starts "We allow..." should better explain the if. Ie something likeIf the link is routed determine whether the user has access unless they have the 'link to any page' permissionCan we also look for or provide a test the other way around ie a test where the user can't add a link because they don;t have access and don't have the permission.
Comment #44
jeroentCreated a new patch that addresses the suggestions given in #43.
Comment #45
jeroentComment #46
jeroent.
Comment #47
wturrell commented- Can reproduce initial problem
- Bug fixed by patch (8.2.x)
- Passes existing tests
- Has a new test
- No UI changes
- Coding standards fine
(NB: not knowledgeable enough to say if fully in scope)
Comment #48
pierremarcel commentedPatch applied, it has solved the problem. Initially looking at the code it seems like all #43 requests have been addressed.
Comment #50
cilefen commentedThank you everyone for the work so far.
::testMenuLinkContentForm and ::testMenuLinkContentFormValidation test conditions are modified by this. I am not saying that's necessarily something to prevent this being committed, but it's something to watch out for.
Nitpick on coding standards: there is not a comma after this array element.
What is this for? ::setUp runs every time.
The last suggestion in the #43 review, "Can we also look for or provide a test the other way around ie a test where the user can't add a link because they don;t have access and don't have the permission." doesn't seem to be in the current patch.(edited)
Comment #51
wturrell commented#50:
2. sorry, apparently had wrong coding style selected, should have spotted in earlier review.
3. removed.
Comment #52
wturrell commentedComment #53
NikitaJain commentedVerified the patch cannot_edit_the-2492513-51.patch on 8.3.x and 8.4.x version. Its working fine, here are the test observations:
1. Patch applied successfully without errors.
2. Tested on Firefox & chrome browser (Ubuntu 14.04)
2. Added a link for 'Login' menu title http://localhost/drupal/admin/structure/menu/manage/account/add
3. Before applying patch: On click to edit link, giving an error "You are not authorized to access this page" for an admin user.
4. After applying patch: An admin user is able to access and change a menu link with value "/user/login" to another one.
Result: Issue is resolved after applying the patch. Admin user can able to access and change the menu link.
Screenshots attached
Comment #55
wturrell commentedNeeds reroll for short array syntax.
Comment #56
gaurav.kapoor commentedComment #57
gaurav.kapoor commentedRe-roll.New short array syntax used.
Comment #58
jofitzFixed a very minor coding standard issue.
And removed the Needs Reroll tag.
Comment #59
NikitaJain commentedVerified and tested with the latest patch on 8.3.x-dev version, working fine screenshots attached in #53
Comment #60
alexpottSaving issue credit. Adding @Shabbir because they provided test evidence with a screenshot, @xjm, @cilefen and myself because we all provided feedback that resulted in changes to the patch.
Comment #61
alexpottCommitted 6c37e3e and pushed to 8.4.x. Thanks!
I think we should consider cherry-picking this to 8.3.x before 8.3.0. Will ask another committer for an opinion.
Comment #64
alexpottBoth @catch and @cilefen are +1 for 8.3.x
Comment #66
Anonymous (not verified) commentedStill it isn't compatible with Taxonomy Menu module , not able to edit menu created using that module with admin menu as parent.