Problem/Motivation
Given this menu link:
menu_test.current:
title: 'Link to current page'
route_name: '<current>'
menu_name: account
An anonymous will not see it in the "account" menu. This is because the access to the route is denied. But if a user reached a page is supposed to be able to reach it again. So, the access to the <current> route should always be granted.
The bug is proved by the attached patch.
Steps to reproduce via UI:
1. Install vanila Drupal and log in as admin
2. Go to /admin/structure/menu/manage/main/add
3. Create a test menu link item. Important: Use route:<current> as link.
4. Save.
5. Check frontend as admin user. The link is visible.
6. Check frontend as anonymous user. The link is NOT visible.
Proposed resolution
Always allow the access to <current> route.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.

Comments
Comment #2
claudiu.cristeaComment #3
claudiu.cristeaThe fix.
Comment #4
claudiu.cristeaComment #5
sk33lz commentedThe patch in #3 still applies cleanly to 8.8.x. I added an additional test to the patch comment.
Comment #10
feyp commentedI just closed #3052019: Menu item with <current> path not visible to anonymous users as a duplicate issue, since it looks like the same issue and the patch is identical. Although the other issue is older, I decided to keep this issue since it already has tests and is ready for review. Carrying over "Needs security review" tag, since I think it is a good idea. Added steps to reproduce via UI from the other issue to the summary.
Comment #11
abhijith s commentedApplied patch #3.After applying this patch the menu link targeting the current page is accessible for anonymous user.
Before patch:

After patch:

Comment #12
manojithape commentedComment #13
manojithape commentedVerified and tested patch #3 on the drupal 9.3.x-dev version. Patch applied successfully and looks good to me.
Testing Steps:
1. Install vanilla Drupal and log in as admin
2. Go to /admin/structure/menu/manage/main/add
3. Create a test menu link item. Important: Use route: as link.
4. Save.
5. Check frontend as an admin user. Observe the link is visible.
6. Check frontend as an anonymous user and observed the link is NOT visible.
7. Now apply the patch and clear the cache.
8. Again check the frontend as an anonymous user and verify the link should visible.
Testing Results:
After applying the patch for anonymous users current link is visible.
Please refer attached Before patch and After patch images for reference.
Moving this ticket to RTBC.
Comment #14
manojithape commentedComment #15
gauravvvv commentedJust out of curiosity, I have a question. Since the link is active for the same page always. means click on the click will refresh the page and nothing to do with it. Do we need an anchor tag over it? Is it useful to have a link for the same page?
Comment #16
larowlanUnchecking credit for those who provided screenshots when we already had them.
Can we get a fail/pass patch here to demonstrate the new test fails as expected.
Thanks
Comment #17
gauravvvv commentedComment #18
feyp commented> Can we get a fail/pass patch here to demonstrate the new test fails as expected.
Yes, we can.
Comment #20
claudiu.cristeaLooks good!
Nit:
Let's strict type the method's return to void.
Comment #21
claudiu.cristeaRef: #15:
Yes, some might want to add an anchor link.
Comment #22
feyp commentedThanks Claudiu for your review. Added the return type hint.
And expanding on #21: You could also use GET parameters, doesn't need to be an anchor. My use case is this module, which currently includes a workaround for this issue that I would like to remove.
Comment #24
chetanbharambe commentedVerified and tested patch #22. (https://www.drupal.org/files/issues/2021-08-16/3008889-22.patch)
Patch applied successfully and looks good to me.
Testing Steps:
# Goto: Install vanilla Drupal and log in as admin
# Go to /admin/structure/menu/manage/main/add
# Create a test menu link item. Important: Use
route:<current>as link.# Save it
# Check frontend as an admin user. The link is visible.
# Check frontend as an anonymous user. The link is NOT visible.
Expected Results:
# User should see link should be visible for anonymous user.
Actual Results:
# Currently, the user is able to see link for admin users only and not for anonymous.
Please refer attached screenshots for the same.
Looks good to me.
Can be a move to RTBC.
Comment #25
alexpottThis is still marked "needs security review". Before this can be RTBC someone needs to do that. I would think we need a comment that shows:
My gut feel is that this change is fine but we need to do some careful thinking about consequences. And we need to do the work.