Problem/Motivation

From #2983179-16: [META] Implement stricter access checking for the media library:

Finally, the media library view has two displays (grid and table), and neither can really be used without a valid state object. Yet there is nothing enforcing that constraint -- if you have the "view media" permission, you can see the media library. So we want to deny access to all displays of the media library view (except the standalone ones at /admin/content/media) if there is no valid state object present.

Proposed resolution

Deny access to all widget displays of the media library view if there is no valid state object.

Remaining tasks

Write patch
Review
Commit

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

seanB created an issue. See original summary.

seanB’s picture

Issue summary: View changes

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

I don't understand the issue summary because I don't know enough about the Media Library implementation details — only today I found out about \Drupal\media_library\MediaLibraryState!

Wim Leers’s picture

Status: Active » Postponed (maintainer needs more info)

Having dug deeper, I think I understand it now. What this is saying, is that the Media Library selection dialog (\Drupal\media_library\MediaLibraryUiBuilder::buildUi() or /media-library) should result in a 403 when it is opened without a valid MediaLibraryState.

However, didn't #3038241: Implement a tamper-proof hash for the media library state already do this? It added \Drupal\media_library\MediaLibraryUiBuilder::checkAccess() with this code:

  public function checkAccess(AccountInterface $account = NULL, MediaLibraryState $state = NULL) {
    if (!$state) {
      try {
        MediaLibraryState::fromRequest($this->request);
      }
      catch (BadRequestHttpException $e) {
        return AccessResult::forbidden($e->getMessage());
      }
      catch (\InvalidArgumentException $e) {
        return AccessResult::forbidden($e->getMessage());
      }
    }

AFAICT that already covers the scope of this issue?

seanB’s picture

The media library view contains 2 page displays that are supposed to be used only within the media library modal (URLs admin/content/media-widget and admin/content/media-widget-table)). This issue is about adding an extra check for a valid media library state when using the page display URLs of the views displays directly.
The access to the /media-library is indeed already handled by the other issues.

Wim Leers’s picture

Ah, I see, this is about adding similar access restrictions to not just the route (which already exists, done in #3038241: Implement a tamper-proof hash for the media library state), but also to the view?

seanB’s picture

Correct :)

Wim Leers’s picture

Title: Deny access to all widget displays of the media library view if there is no valid state object » Deny access to all media library View Displays if there is no valid state object
Status: Postponed (maintainer needs more info) » Active

👍— attempted to clarify the title for the next person looking at this issue :)

seanB’s picture

Here is a first version of the patch. I incorporated the change in #3057370: MediaLibraryState::fromRequest() may result in invalid MediaLibraryState::create() call to prevent that from failing the new tests. We can remove it from this patch once the issue is committed.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Wow, that's much simpler than I expected :D Assuming the test-only patch fails and the other one passes, this is definitely ready!

The last submitted patch, 10: 3038350-10-test-only.patch, failed testing. View results

Wim Leers’s picture

That worked as expected! 👍 🚢

seanB’s picture

effulgentsia’s picture

Status: Reviewed & tested by the community » Needs review

Currently in HEAD, if you go to /admin/structure/views, then for the Media Library view, in the Displays column, you see links for /admin/content/media-widget and /admin/content/media-widget-table. In HEAD, clicking on them causes an unhandled exception, coming from MediaLibraryState::validateParameters(). Because of this, when you edit the Media Library view, and one of those displays, the live preview at the bottom doesn't work.

This patch replaces the unhandled exception with a 403, for all users, including user 1. That then continues to leave the live preview broken.

Is there anything we can/should do here to make the live preview work? And maybe also make the links from /admin/structure/views work? At least for some set of users (like ones with permission to edit the view)? I think that would make it easier for people to make changes to that View.

I don't know if that's really in-scope for this issue, since the live preview is already broken in HEAD, so curious what others think about whether to hold this up on that.

phenaproxima’s picture

Issue tags: +Needs followup

I don't know if that's really in-scope for this issue, since the live preview is already broken in HEAD, so curious what others think about whether to hold this up on that.

I think we should fix that in another stable-blocking issue, which I will file.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Opened #3060603: Live preview is broken when editing the media_library view. I think I'm going to send this back to RTBC, since the bug is pre-existing in HEAD and this issue does not exacerbate it.

phenaproxima’s picture

Issue tags: -Needs followup

Forgot to remove the tag.

alexpott’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Reviewed & tested by the community » Fixed

Nice bug find @effulgentsia. I agree with @phenaproxima that it is not in scope here and we now have the follow-up so that's good.

Crediting @Wim Leers and @effulgentsia for issue review.

Committed and pushed a3ce6e70ed to 8.8.x and 734b9190b3 to 8.7.x. Thanks!

  • alexpott committed a3ce6e7 on 8.8.x
    Issue #3038350 by seanB, Wim Leers, effulgentsia: Deny access to all...

  • alexpott committed 734b919 on 8.7.x
    Issue #3038350 by seanB, Wim Leers, effulgentsia: Deny access to all...

Status: Fixed » Closed (fixed)

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