Problem/Motivation
A recent security fix introduced a regression that affects facets for custom entities. The access check was updated, but it now causes facets to be hidden from anonymous users.
This happens because the new check uses a generic 'view' operation instead of the more specific 'view label' operation, which is the correct permission for this context. Entities that have a custom viewLabelOperation property are affected, as the permission check fails even when users have the necessary access to view the entity label.
Steps to reproduce
- Create a custom entity with a defined viewLabelOperation.
- Set up a facet that uses this custom entity.
- Ensure that anonymous users have permission to 'view label' but not 'view'.
- Navigate to the page with the facet as an anonymous user.
- Observe that the facet is not visible.
Proposed resolution
The solution is to change the access check to use the more specific 'view label' operation, which is the correct permission for this context.
Change the line:
$access_result = $access->access($entity, 'view', return_as_object: TRUE);
to:
$access_result = $access->access($entity, 'view label', return_as_object: TRUE);
This adjustment will ensure that the access check correctly validates against the appropriate permission, allowing facets for custom entities with viewLabelOperation to be visible to users who have the correct permissions.
Remaining tasks
- Create a patch with the proposed resolution.
- Review the patch to ensure it resolves the issue without introducing new regressions.
User interface changes
None
API changes
None
Data model changes
None
Issue fork facets-3545467
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 #5
colinstillwell commentedThank you aneida for reporting this!
I have experienced the same issue.
For our use case, we are having issues with taxonomy terms and we also use https://www.drupal.org/project/taxonomy_access_fix.
When applying the fix in this issue and provisioning permissions to view published term names, this resolved it for us.
Comment #6
agoradesign commentedworks for me as well! I've investigated the problem before and came to the same conclusion, that the 'view label' permission should have been used - then found this patch here. Well done :)
Comment #7
stborchertThis is still happening in version 3 and the patch fixes it there also.
Comment #8
strykaizerFacets support all entity references, not only taxonomies.
The 'view label' permission only exists on taxonomies, breaking the other entity types.
Needs work
Comment #9
ludo.r@strykaizer,
It seems the EntityAccessControlHandler has a fallback to
viewpermission if the entity type deosn't allowview labelpermission.See https://git.drupalcode.org/project/drupal/-/blob/10.6.x/core/lib/Drupal/...
Comment #10
strykaizer@ludo.r awesome... thx for checking.
In that case, this can go in as is.
Comment #11
strykaizerFixed in #3590916
(Sorry, didnt notice it was a duplicate)
Credits overthere