Problem/Motivation
Entities of not permitted bundle are shown in the dropdown. Can they be created too?
Steps to reproduce
TODO, see #11
Proposed resolution
If reproducible, leverage InlineEntityFormBase::getCreateBundles in the right place.
Remaining tasks
- Create step-by-step instructions in the issue summary how to make the issue happen. (This can be done with standard Drupal, by setting Node create/edit permissions)
- Exactly describe what happens: Can invalid bundles be created or are they only in the dropdown?
- Code a failing test that demonstrates the problem
- Code a fix
- Review, commit.
Original Issue Summary
Summary:
When a complex entity inline form is created, there is no check on whether or not the user has access to the entity bundle that is used to create the form. This may allow users to create entities from bundles that they do not have access to normally.
Details:
To generate the complex entity inline form, the determineBundle() method is called to figure out which bundle of an entity type should be used. This uses the method getTargetBundles() to get a list of bundles of an entity type. It then takes the first available value from that list.
No access check is performed on these bundles vs the active user. This means that users can potentially get access to bundles that they are not permitted to.
Reproducibility:
In my own project, this issue allowed a user to get access to an entity form for a bundle that the user had no access to.
I'm not sure how to reproduce this on a standard Drupal install, as it probably requires a custom implementation of the EntityAccessControlHandler class ( as I have in my project ).
However, as far as I can see, the inline entity form module lets Drupal populate the drop-down list of available bundles, which then correctly filters out any entity bundles that are off-limits. Yet it then proceeds to generate a form using an arbitrary element from the bundle list generated by getTargetBundles() to create a form.
Comments
Comment #2
Roensby commentedComment #3
Roensby commentedHere is a suggestion for adding access checks to form generation.
It simply adds a check to the
getTargetBundles()method, to make sure that the user has access to the bundle.Comment #4
Roensby commentedCorrected for missing instantiation of the entity manager.
Comment #5
mhmd commentedThe patch fixed the issue and works fine with custom content entities thanks @Roesby.
Comment #6
Roensby commentedComment #7
bojanz commentedYou can't use EntityManager, it's been deprecated for ages.
Use/inject EntityTypeManager instead.
Comment #8
andrey.troeglazov commentedRecreated patch #4 with using EntityTypeManager.
Comment #9
joachim commentedAFAICT this is already in the code, just not in that method:
Is it maybe the case that something is calling getTargetBundles() when it should be calling getCreateBundles()?
Comment #10
keopxI have two entity reference, and it not works. Only get first item (ordered by bundle alphabetically), not get by accessing rules.
After applying patch #8 it resolved the problem
Thanks @andrey.troeglazov
Comment #11
geek-merlinThis issue can only proceed after some un-mess happens. See IS
Comment #12
geek-merlinAlso there is a related issue with a superb IS and a patch. Please report back if that patch from the other issue fixes this.
- If yes, set status to closed(duplicate)
- Otherwise proceed as noted in the IS
Comment #13
geek-merlinThat code changed a long time ago.