Problem/Motivation
This was reported privately and the security team deemed it could be solved in public
\Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter renders a link regardless of whether the user in context has access.
Steps to reproduce
Use a StringFormatter formatter where the related entity is inaccessible to the user. Presently, a link will be displayed. If the user attempts to navigate to it they may reach a 403.
Proposed resolution
MR 8317 is for 11.x
Display a plain text for the linked entity when the user in context does not have access.
StringFormatter already has a textual fallback for when the entity does not have a canonical template or link_to_entity setting is off.
Remaining tasks
Implement.
User interface changes
Text link may be displayed when user does not have access.
API changes
It may be necessary to install the user entity and add a default user for tests.
Data model changes
None.
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #57 | 3336994-nr-bot.txt | 3.65 KB | needs-review-queue-bot |
Issue fork drupal-3336994
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:
- 3336994-stringformatter-access-r2
changes, plain diff MR !8317 /
changes, plain diff MR !3531
- 3336994-stringformatter-access-r5
changes, plain diff MR !4858
- 3336994-stringformatter-access-r4
changes, plain diff MR !4857
- 3336994-stringformatter-access-r3
changes, plain diff MR !4856
- 3336994-stringformatter-access
changes, plain diff MR !3309
Comments
Comment #3
dpiComment #4
larowlanComment #8
larowlanComment #9
mxr576MR 3309 is HTTP 404, why is that?
Comment #10
dpiIt was hoisted into the security queue. @larowlan reckon we could get it reinstated?
Comment #11
mxr576Our patches from the original sec issue could be re-uploaded here, but most probably an MR would be easier for everyone. Let that be 3039 or a new one.
Comment #12
dpiThe patch was originally based of 3039.
I have the code for the MR locally. I'll push the branch as a new MR if we cant get 3039 back.
Comment #13
larowlan@drumm had to delete it from gitlab, we will need to open a new one, if you've got the branch locally please go ahead dpi
Comment #15
dpiNo worries.
MR !3531 replaces !3309
Comment #16
smustgrave commentedLet me know if this was a wrong way to test.
I added a user field to a content a type.
Made sure anonymous users cannot view information about user
Open private browser and I see the link to the user. This is with the patch.
Comment #17
dpi@smustgrave that might be
\Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceLabelFormatter, which also suffers the same problem in #3246579: Entity reference label formatter may render link to inaccessible entity.The solution/tests are similar. Maybe the issues should be merged?
Comment #18
smustgrave commentedWould be nice. Will let you make that call as #3246579: Entity reference label formatter may render link to inaccessible entity still needs tests so wouldn't want to hold this fix up for that.
But if we keep separate how to best test this one?
Comment #19
dpiIn most cases
StringFormatterlink to the entity its attached to, so you'd need to deny access to view the canonical page. Could do this with a hook_entity_access, or regular permissions.stringfield to an entity (Text (Plain))string(labeled: "Plain text", class is StringFormatter )Then navigate to a page that renders a link via the formatter, such as admin/content overview.
The link will not be visible for users without view access, even though they could see it in a table and edit it, etc.
Comment #22
drummThe fork is no longer private and should be usable as normal again.
Comment #24
kksandr commentedComment #32
kksandr commentedError, wrong fileComment #33
kksandr commentedComment #34
acbramley commented@kksandr you've opened multiple MRs and uploaded multiple patches, can you please close/hide the irrelevant ones and explain your work?
Comment #35
kksandr commented@acbramley Sorry, my mistake. I updated MR to be compatible with the 11.x branch. After that, I tried to apply MR as a patch on my site (Drupal 10.1), but it did not apply, so I separately rerolled the patch for 10.1.x
Comment #36
acbramley commented@kksandr which MR is the correct one?
There was an existing one https://git.drupalcode.org/project/drupal/-/merge_requests/3531
You've created 3 more:
https://git.drupalcode.org/project/drupal/-/merge_requests/4856
https://git.drupalcode.org/project/drupal/-/merge_requests/4857
https://git.drupalcode.org/project/drupal/-/merge_requests/4858
This makes it very confusing to review, please close the incorrect ones.
Comment #39
kksandr commented@acbramley I hid all my unsuccessful attempts, sorry.
Comment #42
mxr576Created a new MR because the old one was targetted 10.1.x and I did not have perm to change that.
Comment #45
smustgrave commentedBummer can't hide 3531 without hiding 8317 so marked in the issue summary
Ran test-only feature https://git.drupalcode.org/issue/drupal-3336994/-/jobs/1841768 which choses all the coverage
Reviewing code and changes make sense.
Only concern I suppose I would have is seeing all the test updates if this would break contrib tests potentially. But doing a deprecation not sure make sense since the link renders a 403.
LGTM
Comment #47
xjmI closed the superfluous merge request. Unfortunately, the canonical one mentioned in the IS has merge conflicts. So this needs those conflicts resolved. (To receive credit for resolving merge conflicts, the conflict and how it was resolved need to be documented on the issue.) Thanks!
Comment #48
mxr576Resolved conflicts caused by added void return type hints.
Comment #49
smustgrave commentedRebase seems good
Comment #50
alexpottWe need to add a change record to cover this change. Also we should mention tests because quite a few have had to change as a result of this change.
Comment #51
mxr576Drafted https://www.drupal.org/node/3459840 based on Alex's suggestions.
Comment #52
acbramley commentedCR reads well. Nice!
Comment #53
alexpottThe tests which are being changed to set up UID 0 do not need this change and should be reverted. Once that's done this can be set back to rtbc.
Comment #54
mxr576Fixed the single one thing that Alex asked and I dared to move this back to RTBC
Comment #55
quietone commentedI read the IS and the comments. Thanks for the up to date issue summary. There are no unanswered questions but there are changes to core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php that alexpott said are not necessary. They are still in the MR. And then, looking at the MR I left a question about changes to another file.
I read the change record and it is easy to follow. It is good that includes what sites should do. Nice work. At first I thought the title could just say that the link is not displayed instead of 'restricts'. But maybe that is a good thing so people are curious and read the notice.
Setting to NW for the 2 comments in the MR.
Comment #56
mxr576Thanks @quietone for your high quality review again, I have fixed your findings, even more https://git.drupalcode.org/project/drupal/-/merge_requests/8317/diffs?co....
Comment #57
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. 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 #58
mxr576Comment #59
smustgrave commentedFrom what I can tell additional feedback has been addressed
Comment #60
mxr576FTR, opened #3468031: StringFormatter does not support entity uri_callback as a follow up, fixing that is not the scope of this issue.
Comment #63
longwaveAlthough this is a bug fix and security hardening I am not committing to 11.0.x or 10.3.x as it is a behaviour change and we do not want to break tests or surprise users that are currently relying on this functionality.
Committed and pushed 4c8c814c10 to 11.x and 1019986cb1 to 10.4.x. Thanks!
Also published the change record.