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

Comments

oknate created an issue. See original summary.

oknate’s picture

Issue summary: View changes

Version: 8.7.6 » 8.7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.7.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

amjad1233’s picture

Category: Bug report » Feature request
StatusFileSize
new76.74 KB
new12.46 KB
new173.4 KB

I couldn't find a button on the UI to delete the task. But when I navigated to `***/delete` manually, it did delete the task. However, two observations were made:
1. Even after deletion, it asked for a "Replacement Image Style". Why couldn't it be removed in the first place?
2. There's a very slim chance someone can delete the task outside of the UI.
- In any case, it does not sound like a bug. (in my opinion)

acbramley’s picture

Version: 9.5.x-dev » 11.x-dev
Category: Feature request » Bug report
Issue summary: View changes
Issue tags: +Bug Smash Initiative

I actually think this is a bug, and it's not just super users that can bypass this access check.

The problem is that all image style entity routes don't have _entity_access requirements, rather they're just checking for a permission.

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'

Since user 1 has all permissions, it gets access, but also any role with administer image styles would have access

acbramley’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new3.1 KB
new3.62 KB

Here's a red/green combo (providing the fix doesn't break anything else) to prove it.

Moved the test from Kernel -> Functional so we have one place to do API based and UI based access checks.

The last submitted patch, 11: 3079235-11-failing-test.patch, failed testing. View results

keshavv’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new81.2 KB

I have applied the #11 pass patch and confirmed that it is working perfectly.
Remove delete permission

  • lauriii committed af3a8ef5 on 11.x
    Issue #3079235 by acbramley, amjad1233, keshav.k, oknate: Media Library...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed af3a8ef and pushed to 11.x. Thanks!

acbramley’s picture

Oh wow didn't expect that, thanks! I wonder if we should do follow ups for the other image style routes? Edit and create both use the permission as well as image effects

lauriii’s picture

Seems fine to have a follow-up for that. I was thinking of asking for those changes here but thought it would be nice to land this for delete route first because it had some pre-existing tests in Media Library.

acbramley’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.