Problem/Motivation
In the case i have an entity which reference entities, if i use "Referenced entities" source in my component and use those referenced entities to display data in my component, i can access to data of entities i should not. No access are checked.
Steps to reproduce
Create a Bundle of node "Recipe" with a field reference to bundles of nodes "Ingredients".
In Recipe display , create a component with a "Referenced entities" which use referenced Ingredients data (nor render Ingredients).
In case i should not access to an ingredient (ex: status is false or access is forbidden), ingredient should not be available, but currently, it displays.
Proposed resolution
In EntityReferencedDerivableContext::getReferencedEntities(), check access to the entity with access method.
Issue fork ui_patterns-3516063
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 #2
just_like_good_vibeswe need that, i take this issue
Comment #4
just_like_good_vibesMR !545 is ready. The scope is a bit larger than the title: the same problem exists in the other sources that give data from things Drupal protects, so the MR fixes them all the same way. The rule is the one core uses before it renders something: check access with an access result object, keep the cacheability of that result even when access is denied, and give nothing when it is denied.
What changes:
- Referenced entities (
EntityReferencedDerivableContext): the referenced entity is translated for the display language, then "view" access is checked on that translation, only allowed entities become contexts, and the field index now selects a field delta, so a denied delta gives nothing instead of the next entity. This is what core does inEntityReferenceFormatterBase::getEntitiesToView().- Field values (
FieldValueSourceBase, used by the field property sources): "view" access on the field is checked, like core does before a formatter runs. Example: the email of another user is no longer readable.- Blocks (
BlockSource): the block plugin access is checked before build(), like a placed block.blockAccess()now counts.- Entity links (
EntityLinksSource): the URL access is checked, like a link element. No more edit or delete URL for users who cannot open them.To carry the cacheability, sources and derivable contexts implement
RefinableCacheableDependencyInterfaceandComponentElementBuildermerges it into the component render array. Interfaces are not changed.new tests, all red on 2.0.x before the fix: one kernel test per source, a kernel test that renders a component and checks what the renderer bubbles, and a functional test where a hidden referenced node shows up once published with a warm page cache, the same scenario as core's Layout Builder cache tags test. The existing entity link fixture now runs as an editor, because an edit URL for an anonymous user was the bug.
This also fixes the wrong language of referenced entities reported in #3562508: Is Ui Patterns with sdc usage compatible with multilingual websites?, because translation and access have to happen at the same place.
Comment #5
pdureau commentedNot tested on my local environement but the MR looks good:
RefinableCacheableDependencyInterfaceandRefinableCacheableDependencyTraitUrl::access()inEntityLinksSourceAccessibleInterface::access()inBlockSourceComment #7
just_like_good_vibes