Generated with the help of an LLM.
The MR and the comment below were written with help from Claude; I reviewed and tested them.
Background information
This was originally reported as a private security issue, but has been approved for handling in the public queue by the Drupal Security Team.
- security.drupal.org private issue: https://security.drupal.org/node/183941
(included for reference. Please do not report access denied as an error.)
Problem/Motivation
When using hook_ENTITY_TYPE_access to deny access it will only work when the route is using _entity_access
On admin/config/media/image-styles the user will no longer see edit and delete links, but will still see the flush link.
The code below will effectively block access to the delete form, but the edit form is still accessible.
And the user is still able to create a new image style and flush an existing image style.
This problem also applies to responsive image styles.
So behavior of hook_ENTITY_TYPE_access is inconsistent and will not always prevent access as expected.
Steps to reproduce
/**
* Implements hook_ENTITY_TYPE_access().
*/
function foo_image_style_access() {
return AccessResult::forbidden('No one should edit or delete this image style.');
}
Proposed resolution
Adding _entity_access: 'image_style.edit' to the routing definition for the edit and
flush forms will ensure that the access check is applied consistently, although the flush link remains visible.
Adding _entity_access: 'image_style.create' to the routing definition for the add form
will ensure that the access check is applied consistently.
Maybe the documentation needs improvement?
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3563028
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 #5
deruina commentedComment #6
deruina commentedI opened an MR that moves the image style and responsive image style admin routes from
_permissionto entity access, like the image style deleteroute already does. Add and duplicate use
_entity_create_access, since_entity_access: 'image_style.create'needs an entity in theroute and the add form has none. Edit, flush and delete use
_entity_access.I also put the image effect add/edit/delete routes under
image_style.update. Changing an effect saves the style, so without that a hook thatblocks editing a style could still be bypassed through the effect forms. The Flush link in the list now only shows when the user has update access.
Nothing changes for sites without these hooks, because both entity types use the same permission as their admin permission. Kernel tests for both modules
turn on a deny hook and check every route; they fail without the routing changes.
AI-Generated: Yes (I used Claude to help write the code and tests. I reviewed and tested it before pushing.)
Comment #7
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #8
deruina commentedRebased on main and added #[ShareEnvironment(FALSE)] to the two new kernel tests, which core requires since #3623409. PHPStan and the tests pass locally.
Comment #9
idebr commentedTest only changes fail as expected: https://git.drupalcode.org/issue/drupal-3563028/-/jobs/14259188
Change looks complete to me, settings to RTBC.