Problem/Motivation
Hi, I'm running into a problem that the `entity_reference_label` formatter does not check the URL access to the entity, but only relies on checking the access to the 'view label' operation and I'm getting invalid links.
Steps to reproduce
This can be reproduced by displaying a link to the user. The user always returns AccessResultAllowed for the 'view label' operation, but the direct view link (the 'view' operation) requires additional permissions.
Proposed resolution
I suggest adding an additional access check to the generated URL and if it is not available, output the label as plain text.
Remaining tasks
See #9.
Code review
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 3386313-nr-bot.txt | 90 bytes | needs-review-queue-bot |
Issue fork drupal-3386313
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
kksandr commentedComment #3
kksandr commentedComment #4
kksandr commentedComment #6
kksandr commentedComment #7
kksandr commentedComment #8
smustgrave commentedThank you for including test-only patch.
Only question would be the todo linking to follow up issues but will see if committers think that's an issue.
LGTM
Comment #9
quietone commented@kksandr, thanks for issue and the MR!
I'm triaging RTBC issues. I read the IS, which is missing several sections. I have restored those in case they are needed and so we have the 'remaining tasks' section. I read the one comment that gives thanks for the test only path and leaves a question for the committer team. I do not see evidence of a code review.
I applied the diff and read the comment with the @todo. The comment should be wrapped correctly and instead of referring to a file it should refer to a class, or method. That said, I then ran the test without the added user to see the failure. That was at
/var/www/html/core/lib/Drupal/Core/ParamConverter/EntityConverter.php:149which also has a todo. And that todo refers to https://www.drupal.org/node/2934192 which is removing the block of code where the test is failing. It seems to me the @todo should point to that issue. Unless, I am missing something. Then, when that is fixed the creation of the user can be removed. (I tried that by applying that patch and removing the creation of the user and the test passed). Also, the anonymous user should only be created in the test where it is needed, instead instead of in the setup.In testLabelFormatter, the value
build[0]['#url']is always unset. Surely, there should be a test for when it is set.Setting to needs work for the above.
Comment #12
kksandr commentedComment #13
kksandr commentedComment #14
smustgrave commentedSeems all the todos have been removed/addressed
https://git.drupalcode.org/issue/drupal-3386313/-/jobs/1896646 shows the current test coverage is still there
The test chunk added in https://git.drupalcode.org/project/drupal/-/merge_requests/8447/diffs?co... believe addressed the test scenario where the URL is not unset.
Comment #15
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #17
mxr576Comment #18
smustgrave commentedMissed the additional threads after I marked RTBC but believe feedback has been addressed
Comment #19
catchOne question on the MR.
Comment #20
catchThanks that looks better to me.
Comment #21
longwaveSimilar to the fix in #3336994: StringFormatter always displays links to entity even if the user in context does not have access this needs a change record to explain the behaviour change to users (and tests) that might be relying on the current behaviour.
Comment #22
mxr576It may feels copy-paste... because admittedly, it is! :)
The "Label" entity reference field formatter now restricts links for inaccessible destinations
Comment #23
longwaveThanks, the change record reads well and the code changes look good too.
Comment #25
larowlanCommitted to 11.x
I think it is worth back-porting this to 10.4 for API compatibility and because its a bug.
I don't think we can back port it to 10.3/11.0 because the behaviour change could be disruptive.
Needs re-roll for 10.4.x
Published the change record.
Thanks
Comment #28
larowlanI backported this to 11.1.x
Setting to 10;5.x, but also needs backport for 10.4.x
Comment #29
bkosborneIsn't there a legit use case for still linking to pages a user does not have access to? Like if the entity being linked to is not available to anonymous users, but is available to authenticated users. We'd still want the link to that entity because we can log the user in automatically when they encounter a 403 and are logged out.
Comment #30
mxr576Yes, you may want to suggest the user to log in because afterwards they **may** get access to something, but at the same time, you may not want to disclose information about the entity behind the scenes, like the title/label could already hold such information.
So in this cases you actually would like to expose a Call To Action based on a deliberate decision and driving the user.
Comment #31
bkosborneBut I can't do that anymore with this change, right? At least, not using this field formatter.
Comment #32
chi commentedDoes this duplicate #3293287: EntityReferenceLabelFormatter returns a link even if the user only have "view label" access?
Comment #33
smustgrave commentedThink 10.4 has been missed but could still do 10.5
Comment #35
smustgrave commentedBackport was clean.
Comment #36
xjmI agree that this is a good choice for a 10.5.x backport. We're down to the wire here on the minor and technically the commit freeze has started, but maybe someone can look at it today.
Comment #37
xjmThis is major.
Comment #38
xjmI did a code review with the context that this has already been committed to D11. I also compared the 10.5.x MR to the 11.x commit and confirmed they match.
Waiting for the test-only pipeline.
Comment #39
xjmHm, the test-only pipeline seems to have barfed:
Will try a requeue.
Comment #40
xjmI reran the job with the same result. Someone could try it locally?
Comment #42
xjmI requeued a full pipeline job as per @fjagrlin our test-only job expired after a week. So hopefully with a new pipeline we can run it.
Comment #43
xjmOK, the test-only job worked this time and failed this time, with:
That's... not exactly the fail I was expecting, and it also demonstrates that the custom assertion message is not useful because it will never be displayed since it fails on an undefined array key rather than the actual assertion. It would probably be better to assert the existence of it first, I think, since (upon careful review), that is what is being added.
But changing that is out of scope for a backport, so tagging for a followup.
Comment #46
xjmFollowup is #3532932: Improve EntityReference/EntityReferenceFormatterTest::testLabelFormatter() to fail in an explicit way when the fix is reverted.
Committed to 10.6.x. I also backported it to 10.5.x as a major bugfix. Changing access behavior is slightly disruptive, but in this case the benefit outweighs the disruption IMO.
Thanks everyone!
Comment #48
danyg commentedUnfortunately, this update removed links of taxonomy term entity references which I have permission to view, but the $uri_access->isAllowed() always returns with FALSE
I still can reach the taxonomy/term/{term-id} pages without any issues and according to the view which handles the taxonomy pages, it gives full access to the taxonomy listing page.
I've been debugging it for a few hours but I haven't found it out yet what's wrong.
UPDATE: it seems I have a conflict with the patch I used from https://www.drupal.org/project/drupal/issues/2778345