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

  1. Create a custom entity with a defined viewLabelOperation.
  2. Set up a facet that uses this custom entity.
  3. Ensure that anonymous users have permission to 'view label' but not 'view'.
  4. Navigate to the page with the facet as an anonymous user.
  5. 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

Command icon 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

aneida created an issue. See original summary.

aneida changed the visibility of the branch 3545467-incorrect-access-check to hidden.

aneida changed the visibility of the branch 3545467-incorrect-access-check to active.

colinstillwell’s picture

Thank 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.

agoradesign’s picture

Status: Active » Reviewed & tested by the community

works 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 :)

stborchert’s picture

Version: 2.0.10 » 3.0.x-dev

This is still happening in version 3 and the patch fixes it there also.

strykaizer’s picture

Status: Reviewed & tested by the community » Needs work

Facets support all entity references, not only taxonomies.
The 'view label' permission only exists on taxonomies, breaking the other entity types.

Needs work

ludo.r’s picture

@strykaizer,

It seems the EntityAccessControlHandler has a fallback to view permission if the entity type deosn't allow view label permission.

See https://git.drupalcode.org/project/drupal/-/blob/10.6.x/core/lib/Drupal/...

strykaizer’s picture

Status: Needs work » Reviewed & tested by the community

@ludo.r awesome... thx for checking.
In that case, this can go in as is.

strykaizer’s picture

Status: Reviewed & tested by the community » Fixed

Fixed in #3590916
(Sorry, didnt notice it was a duplicate)

Credits overthere

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.