Media Library image style shouldn't be able to be deleted through the UI.

Created on 4 September 2019, almost 5 years ago
Updated 12 July 2023, 12 months ago

Problem/Motivation

1) Login as a user with "administer image styles" permission
2) Go to /admin/config/media/image-styles/manage/media_library/delete
3) Submit form

Expected. You should not be able to do this.

Actual: "The image style Media Library thumbnail (220x220) has been deleted."

It works when not using the UI, see MediaLibraryAccessTest::testMediaLibraryImageStyleAccess()

The problem is the superuser bypasses access, because image_style routes are using permission checks instead of entity access checks.

entity.image_style.delete_form:
  path: '/admin/config/media/image-styles/manage/{image_style}/delete'
  defaults:
    _entity_form: 'image_style.delete'
    _title: 'Delete'
  requirements:
    _permission: 'administer image styles'

This then skips the entity access hook in the media_library module.

/**
 * Implements hook_ENTITY_TYPE_access().
 */
function media_library_image_style_access(EntityInterface $entity, $operation, AccountInterface $account) {
  // Prevent the fallback 'media_library' image style from being deleted.
  // @todo: Lock the image style instead of preventing delete access.
  //   https://www.drupal.org/project/drupal/issues/2247293
  if ($operation === 'delete' && $entity->id() === 'media_library') {
    return AccessResult::forbidden();
  }
}

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

TBD

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

11.0 🔥

Component
Media 

Last updated about 1 hour ago

Created by

🇺🇸United States oknate Greater New York City Area

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.69.0 2024