Entity access is incorrect after updating an entity

Created on 9 December 2016, almost 9 years ago
Updated 11 February 2025, 9 months ago

Problem/Motivation

Symptom:

After saving an existing node or other entity, further access checks on that entity are incorrect for the remainder of the request.

Occurs more often when you have some custom access logic in hook_node_access(), hook_node_access_record(), hook_entity_access(), etc.

NOTE: This only happens with subsequent access checks within the same request.

Problem:

EntityAccessControlHandler statically caches calls to ::access(). There appears to be no invalidation of that cache when an entity is updated.

Steps to reproduce:

See patch with test.

Proposed resolution

Invalidate the static access cache (EntityAccessControlHandler::$accessCache) for an entity when the entity is updated.

It's not clear how/where that invalidation should happen.

Workaround:

Manually invalidate the entire static cache before subsequent access checks.

Drupal::entityTypeManager()->getAccessControlHandler('ENTITY_TYPE')->resetCache();

This can incur a performance hit since it resets the cache for ALL access checks.

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

entity system

Created by

πŸ‡ΊπŸ‡ΈUnited States milesw Providence, Rhode Island

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024