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.

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

Issue fork drupal-3563028

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

prudloff created an issue. See original summary.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

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

deruina’s picture

Issue summary: View changes
deruina’s picture

Status: Active » Needs review

I opened an MR that moves the image style and responsive image style admin routes from _permission to entity access, like the image style delete
route already does. Add and duplicate use _entity_create_access, since _entity_access: 'image_style.create' needs an entity in the
route 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 that
blocks 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.)

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new2.24 KB

The 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.

deruina’s picture

Status: Needs work » Needs review

Rebased on main and added #[ShareEnvironment(FALSE)] to the two new kernel tests, which core requires since #3623409. PHPStan and the tests pass locally.

idebr’s picture

Status: Needs review » Reviewed & tested by the community

Test only changes fail as expected: https://git.drupalcode.org/issue/drupal-3563028/-/jobs/14259188

Change looks complete to me, settings to RTBC.