Problem/Motivation

ReferencedEntityAccessControlHandler has two correctness problems related to cache metadata and access result semantics.

1. checkAccess() returns AccessResult::allowed() with no cache tags.

When a parent entity grants access, the result is returned without attaching any cacheable dependency. The cached access result is therefore never invalidated when the parent entity changes (e.g. is unpublished, deleted, or reassigned). Any page that renders a subentity may serve stale access decisions until the cache is manually cleared.

// Current — cache tags from the parent entity are never attached.
if ($entity_parent->access($operation)) {
  return AccessResult::allowed();
}

Fix: add the parent entity and the subentity itself as cacheable dependencies.

if ($entity_parent->access($operation)) {
  return AccessResult::allowed()
    ->addCacheableDependency($entity_parent)
    ->addCacheableDependency($entity);
}

2. checkCreateAccess() returns AccessResult::forbidden() instead of AccessResult::neutral().

When no referencing field is found for the given bundle, forbidden() is returned. This hard-blocks any other access control handler or hook_entity_create_access() from granting access, including the superadmin bypass. The correct return value when this handler has no opinion is neutral().

// Current — hard-blocks other access control mechanisms.
return AccessResult::forbidden();

// Fix — defers to other handlers.
return AccessResult::neutral();

Remaining tasks

  • Add addCacheableDependency() calls on the AccessResult::allowed() return incheckAccess().
  • Replace AccessResult::forbidden() with AccessResult::neutral() incheckCreateAccess().
  • Add a kernel test covering cache tag propagation and the neutral fallback incheckCreateAccess().

Issue fork subentity-3593905

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

macsim created an issue. See original summary.

smavri made their first commit to this issue’s fork.

smavri’s picture

Status: Active » Needs review

macsim’s picture

Issue summary: View changes
macsim’s picture

Status: Needs review » Fixed

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.

macsim’s picture

Issue summary: View changes
macsim’s picture

Version: 3.x-dev » 3.0.x-dev
macsim’s picture

Status: Fixed » Closed (fixed)