Problem/Motivation
1. Create a node
2. Assign anonymous user as the author
3. Edit the node
4. Change auther
Actual behavior
The author field is pre-filled with: - Restricted access - (0)
Expected behavior
The author field is pre-filled with: Anonymous (0)
Proposed resolution
Remaining tasks
User interface changes
API changes

| Comment | File | Size | Author |
|---|---|---|---|
| #99 | 2471154-91.patch | 13.13 KB | amateescu |
| #95 | 2471154-95.patch | 13.29 KB | amateescu |
| #91 | interdiff.txt | 1.76 KB | amateescu |
| #91 | 2471154-91.patch | 13.13 KB | amateescu |
| #85 | interdiff.txt | 1.37 KB | amateescu |
Comments
Comment #1
celdia commentedThe same problem with me. Someone have any idea?
Comment #2
celdia commentedThis look good for me.
Comment #3
googletorp commented#2 Your solution wont work, as it will give access to the user profile for the anonymous user, which we don't want.
Comment #4
celdia commentedYes, I had not seen it. Thanks.
Comment #5
googletorp commentedI talked with Berdir about this.
We could make it configurable if access checks on labels is needed (probably the prettiest solution, but might be to big a change right now).
The other solution is just to not access check for users (this is not considered privileged information anyways, and we do it in the autocomplete anyways.
I've added a patch which took the latter approach, which is a fairly simple change.
Comment #6
googletorp commentedAdd test case and update status on issue.
Comment #8
googletorp commentedI updated the breaking test from link, which according to Berdir should be fine, since the User label is not treated as confidential (you can view it in autocompletes anyways).
Comment #9
aspilicious commentedI'm not really happy with the hardcoded fix...
It will cause a lot of issues where other (contrib) modules will run into the same issue...
Comment #10
berdirYeah, as discussed in IRC, I think we need to move that method into the selection handler plugins, so that user can override it.
Comment #11
googletorp commentedI'm not sure about where the line goes with API changes, as we're in beta now. Is it possible to do this with the configuration solution and still being able to get this committed?
Otherwise I would rather fix the bug and open an issue for 8.1.x for now.
Comment #12
amateescu commentedAdding a new method on the selection handler is just an API addition so I think it's pretty safe to do in the beta cycle :)
Comment #13
googletorp commented@amateescu It's actually not that simple. EntityAutocomplete::getEntityLabels Is called in a few places:
• \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUriAsDisplayableString (for entities)
• \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid::valueForm
• \Drupal\user\Plugin\views\filter\Name::valueForm
To maintain consistent behavior, we would need to stop using EntityAutocomplete::getEntityLabels if we want to move the code, we can't actually remove the method, but if it's not used, it can become depricated.
The tricky thing is that LinkWidget::getUriAsDisplayableString used this for links to entities. If this is moved to the selection handler, then how would we handle this?
I guess either LinkWidget code would need to be rewritten and we wouldn't have a centrilized way to get the entity labels.
So to put it short, I have a hard time seeing, how we can actually solve this, going this direction with Drupal being in beta.
The best solution I can think of, would be to use a different operation for the access call, fx "view_label". Reading through the documentation, it seems that there isn't a limit to what the operation can be. We could for the entity class add a simple.
That would negate the change for all entities, making it work as usual, but entities could catch this in the access function on the specific entity class if needed, making this usable for contrib.
Any thoughts on this?
Comment #14
amateescu commentedHm,
LinkWidget::getUriAsDisplayableString()is tricky indeed. Although, inEntityAutocomplete::getEntityLabels()we can always instantiate a "minimal" selection plugin based only on the target type of the passed-in entities, it would probably be a bit too heavy on the performance side.I'm ok with the 'view_label' solution if everyone else likes it too.
Comment #15
googletorp commentedI've attached a patch which used the fact that $operation can be anything and is pretty loosely documented.
This patch will allow contrib to do something similar and wont effect the existing APIs.
Comment #16
googletorp commentedBumping to Major, since:
• This is a pretty bad UX issue
• There is no work around
• This will effect contrib as well
Comment #17
givingxsharing commentedI'm in DrupalCon LA. I'm applying the patch :-)
Comment #18
googletorp commented@givingxsharing great. I'm not at con, but you can catch me in IRC if you have any questions.
Comment #19
givingxsharing commentedI couldn't duplicate this issue (before applying the patch).
Comment #20
googletorp commentedI've uploaded the a patch containing the new test that testes this behavior. This should be failing.
You can manually run Drupal\node\Tests\PageEditTest with this patch applied to test if this still is a problem. The test still fails for me on 8.0.x
Comment #21
googletorp commentedRerolled the patch from #14 since it doesn't apply anymore.
Comment #24
duaelfrI followed the steps to reproduce.
Before patching:

After patching:

I also read the code and I've seen nothing strange. I checked that we still had tests for other restricted entities and we do.
Thanks for your work!
Comment #25
amateescu commentedLet's try and get some entity system maintainer(s) to chime in here since it's not a very straightforward change.
Comment #27
xanoLabels *can* give away a lot of sensitive information. Even if we don't show the label, matching user input and then returning a result will tell users that some entity with that label exists.
However, if that is no concern among the other reviewers, then here's a more technical review of mine:
This MUST be done in entity types' access handlers.
This MUST be done in the user entity type's access control handler.
Use a
usestatement instead of the FQN in a type hint.Comment #28
xanoThis addresses the feedback I gave in #27.
The reason I rolled this patch myself, is that I wanted to show why the location of the original access code was wrong:
1) All access control logic MUST reside in entity access control handlers.
EntityInterface::access()is merely a convenience wrapper.2) By changing the operation in
EntityAccessControlHandlerwe pretended we're not actually checking access for the view label operation anymore. This prevented anyone from responding to hook invocations for this operation, for instance. I moved this check toEntityAccessControlHandler::checkAccess(), where is simply returns the access for the view operation. This makes sure that all code can still respond to the view label access check and implement the hooks for this specific operation. The fact that we call$this->access()for the view operation, means the full stack of access control checks are executed for that operation as well.Comment #29
klausiThe doc block on this method needs to be fixed, still talks about the "view" access.
So you are inventing a new operation "view label" here? Then that needs to be documented as one of the usual operation strings at EntityAccessControlHandlerInterface.
entity_load() is deprecated, let's not add more calls to the code base. Use User::load() instead.
Comment #30
xanoWe shouldn't document implementation details on interfaces. If anything, this must be documented on
EntityAccessControlHandler.Comment #32
claudiu.cristeaI wonder if this is not related to #2322525: Add separate SelectionHandler for entity_reference fields using user entity used in Author context.
Comment #33
googletorp commentedThere seems to be several places, where we are having these issues, see this question on Drupal Answers.
Basically this is a problem on content types as well (which are config entities). Maybe we need to make this a separate issue, but would be great if we can find a generic solution.
Comment #34
thenchev commented29.1) Changed to view label.
30 added view label to EntityAccessControlHandler.
3. Updated to user load.
Some more small changes i noticed.
Comment #37
thenchev commentedAdded fix for the tests. Hope this is the right way.
Comment #40
thenchev commentedShould address the last failing test.
Comment #41
berdirI don't think this is correct, if this doesn't have any test fails, then we are missing test coverage. Unlike users, we always considered it to be a (security) bug if it is possible to view node titles of nodes you do not have access to, e.g. due to using the node grant system.
I'm not sure why we need to add special cases to any access control handlers except user with the default fallback that's in place now? Are they not calling the parent if they don't have something to say?
I can't say I really like the approach but I also don't have a better idea. But we need to document this view label thing somewhere. Possibly on EntityAccessControlHandlerInterface.
I think we're also missing tests.
Note: This problem doesn't just affect widgets, it also affects formatters. If you are using user reference fields, then the default entity reference formatters won't show the reference at all if you don't have the access user profiles permission. The only one that works is "Author" because that doesn't do access checking but that doesn't allow to configure the output (e.g. link or not link).
Comment #42
thenchev commentedDocument view label on EntityAccessControlHandlerInterface.
Added new var in EntityAccessControlHandler to use when we want label to be shown without access check.
Comment #43
slashrsm commentedChange now seems to be non-BC breaking which is good. I don't know if we want to add additional test coverage for things @Berdir mentioned in #41.
Comment #44
slashrsm commentedComment #45
berdirYou should not make unrelated code style cleanups unless they are on the very lines you are already changing anyway. This makes it harder to review and makes clashes with other issues more likely.
This is not correct and requires that specific implementations have to do something.
What that flag should do is automatically map $op view label to view unless viewLabelOperation is set to TRUE. No access control handler except the default class and user must be changed in this issue.
Comment #46
thenchev commentedTried to remove all unrelated changes and made changes accordion to #45.2
Comment #47
berdirThis should say something like this:
Allows to grant access to just the labels.
By default, the "view label" operation falls back to view. Set this to TRUE to allow to return different access when just listing entity labels.
Other than that, looks clean to me now. As said, some tests would be great that test this a bit more explicitly.
Comment #48
amateescu commentedShouldn't this be moved to the beginning of the method? With the current code, when the 'if' condition is TRUE and we change the operation to 'view', that's what will be stored in the static cache, and, on subsequent 'view label' checks, the static cache will not be used because we stored the info only for the 'view' operation.
This defeats the purpose of the test, which was to check an entity with no 'view' or 'view label' access.
Here's a patch that adds dedicated test coverage and fixes 2. above. I didn't fix 1. as well because I might be missing something.. it would be good to get some confirmation on that.
Comment #50
amateescu commentedHm, let's restrict testing for the 'view label' operation to the entity_test_label entity type only.
The question in #48.1 still remains though :)
Comment #51
Trupti Bhosale commentedApplied the patch in comment #50 and verified the fix, but still 'Restricted Access' is displayed in Authored By field.Attached snapshot for reference.
Comment #52
swentel commentedI'm a bit concerned about the naming, in that sense that it might be mis-used in contrib or custom code. Maybe be more explicit, and be something like 'view admin label' ?
Comment #53
durgeshs commentedComment #54
durgeshs commentedConfirm as already stated in #51, applying patch #50 still doesn't solve the issue.
Comment #55
berdirRe #52: Why admin label and why do you think it would be mis-used? Note that this doesn't just apply to the widget, it applies in exactly the same way when using a formatter too. There it is even worse as the user name is never displayed. The only reason this isn't visible out of the box is because node uses a special author formatter that doesn't check permissions.
Comment #56
swentel commented@Berdir hmm yeah, didn't know about AuthorFormatter implementing checkAccess(). Also didn't know that viewing the label of users is considered ok (which I can live by though).
I'm confused by a change in the test though:
Shouldn't the check for user stay and now actually show the label then ? Or am I missing this completely ? Maybe I should actually test out the patch :)
Also, maybe rename viewLabelOperation to viewLabelAccess ? Just a suggestion, it sounds better in my head for some reason, but then again, I'm not a native English speaker.
Comment #57
berdirThe reason that it doesn't work is because UserAccessControlHandler has an explicit check for the anonymous user. We need to move view label above that and check that first, not in the switch.
Shows that we're still missing test coverage for the user case.
That's what we always did. You can always view the username, but you can't always visit the user profile page. The view/view label access operation thing doesn't fully match that, but I guess it's as close as we can get. In a better world, the user profile would possibly be a separate entity type (profile.module) that you'd view, not the user entity itself. Or something like that I guess. But we have to deal with what we have.
Comment #58
mariancalinro commentedI will move the label access check above the anonymous user check.
Also, I will improve test coverage.
Comment #59
mariancalinro commentedComment #60
mariancalinro commentedComment #61
mariancalinro commentedComment #63
mariancalinro commentedComment #65
mariancalinro commentedComment #67
mariancalinro commentedI have no ideea why the test fails. It asserts that a regular user has no access to create/update/delete/view users, and it fails for each of theese assertions.
However, as far as I know, a regular user shouldn't have access to these operations for user objects.
Comment #68
berdirYou're falling into the uid 1 trap :)
The first user that you're creating gets the UID 1, because this is a kernel test where there is no user by default. So the first one that you create is uid 1 and can do everything.
Explicitly pass ['uid' => 2] to the first createUser() call that you set as the current user. Then the test passes for me.
Comment #69
berdirDid you test manually with the node author widget? Wondering if we have any existing tests that we should be able to update to cover this, if not, I think we should also have an integration/UI test that makes sure editing a node with uid 0 as author is shown correctly.
Comment #70
mariancalinro commentedComment #71
mariancalinro commentedI tested manually with the node author widget, and it works now. I know of no existing tests for this.
Also, I think this should be changed to 8.1.x. I wrote the patches based on 8.1.x and they apply cleanly on 8.0.x. I think the relevant files have no difference between 8.0.x and 8.1.x.
Comment #72
swentel commentedtestbot runs against 8.0.x, so that's fine :)
Comment #73
berdirThe test code in NodeEditForm::checkVariousAuthoredByValues() would be very easy to extend to check for this. It sets the author to the anonymous user (in a way that shouldn't be supported IMHO but that's a different topic). And later on it goes back to the edit form. You just have to refactor that a bit to use drupalGet() to got the edit form and check the value in there.
Then also provide that as a test-only patch (possibly with the other new tests too but they are mostly specific to the new operation and won't really do anything without the new code anyway)
Comment #74
amateescu commentedHere's a more specific test of the widget value, as suggested by #73.
Comment #75
berdirLooks perfect to me but the real patch is 0 bytes :(
Comment #77
amateescu commentedNow with more patch!
It would be great to get this into 8.0.3.. it's quite an embarrassing bug :/
Comment #78
berdirIndeed.
Comment #79
berdirdo we need a short CR to explain the new operation/flag?
Comment #80
amateescu commentedA short CR can't hurt :)
But I just remembered that #48.1 was not answered yet, I still think that the new code there should be moved to the top of the method. Any thoughts on that?
Comment #81
amateescu commentedWrote a (not so) short CR in the meantime: https://www.drupal.org/node/2661092
Comment #82
googletorp commentedThis looks really good, would be nice to get rid of this for 8.0.3. Do we need to make the CR pre or post commit?
Comment #84
berdirMissed #48.1: Yes, you're right, that should move up, agreed.
We need the CR first, as a draft. Doesn't need much, just explain the new operation/use case and how to customize it based on the user example.
Comment #85
amateescu commentedAlright, here we go. The CR is already written, see #81 :P
Comment #86
berdirOk, RTBC if green. Thanks!
Comment #87
catchentites.
Why does this not allow access to authenticated user labels to users that can't view them? It looks like it does reviewing visually.
I also can't see that tested explicitly - we should specifically assert that users that don't have access to view an authenticated user's account still are unable to see their username.
Comment #88
berdirTalked to @catch about the second point.
We should rewrite the comment to clarify that this check is where it is so that labels for all users, including the special anon user can be viewed.
It's too focused on anon user right now, as it tries to explain why we moved it up.
Comment #89
catchComment #90
catchTalked to Berdir in irc, I got confused because of the following:
- the issue title, description, and comments in the patch all talk about the label for the anonymous user only, but auth user labels are only accessible to users with 'access user profiles' permission at the moment.
- Also I was trying to think of a situation where a site might rely on this behaviour, but you'd only not see user labels anywhere if you disable 'submitted' from node types and don't use comments. If you do that, this patch doesn't change things for you anyway, so it shouldn't really be possible to rely on the buggy behaviour.
Updated the title but the comment could use updating too.
Comment #91
amateescu commentedFixed #87.1 and improved the comment from
UserAccessControlHandler::checkAccess().Comment #92
berdirentites, classic typo :)
Looks good to me, back to @catch.
Comment #93
berdirComment #94
catchNeeds a re-roll for 8.1.x
Comment #95
amateescu commentedRerolled for 8.1.x. The patch in #91 still applies cleanly for 8.0.x :)
Comment #97
catchCommitted/pushed to 8.1.x, thanks!
The protected property added to the base class is something we'd normally avoid in a patch release, but given this is an actual bug it might be worth making the change, but leaving RTBC for 8.0.x a bit longer.
Comment #99
amateescu commentedThanks @catch! Re-uploading #91 for 8.0.x, just so it's clear what can be committed :)
Comment #100
chx commentedHow did this got into 8.1.x even without a secteam nod?
Comment #101
berdirBecause we've established that this is/was currently a buggy, broken behavior and fixing it is absolutely in line with how this is handled everywhere else and we can not imagine a scenario where this would make anything visible that wasn't already? It's a new operation that nothing except autocomplete calls.
also, "Needs security review" is a pretty good way to put an issue to sleep for.... a very long time.
Comment #102
amateescu commentedFYI: this issue allows a very simple fix for #2634158: Referencing a block that has conditions leads to 'Unrestricted access' for label and there's also a small followup for this patch: #2692091: Use the new 'view label' entity access check in the entity reference label formatter
Comment #103
catch@chx I gave it an in-depth review from a security standpoint and discussed it at length with Berdir in irc, as is documented above. Also klausi reviewed this a while back. Who else did you have in mind to review it?
Comment #104
amateescu commentedPer #101 and #103, I think we can move this back to RTBC.
Comment #105
xjm8.0.x is now frozen for its final patch release, and this is already fixed in 8.1.x so will be coming out in two weeks! Hooray!
Comment #107
amateescu commentedThe change record for this issue was still a draft, pending the commit of this patch to 8.0x. Since that won't happen anymore per #105, I just published it: https://www.drupal.org/node/2661092