Problem/Motivation

This was originally reported as a private security issue but cleared by the security team for a public issue
Drupal's media preview endpoint accepts a caller-supplied media UUID and embeds the media label in a response header. During validation, the unpublished media item at /media/1 was not directly viewable and returned 404, but the preview endpoint still returned 200 and exposed Drupal-Media-Label: Hidden Media Label. The request only needed a text format with media_embed enabled and the expected preview header. This shows the preview code path leaks media metadata without enforcing media view access.
Impact

Any user who can reach the preview endpoint for a media-enabled text format can enumerate labels of unpublished or otherwise hidden media items when their UUIDs are known.

Relevant vulnerable code blocks:

public function preview(Request $request, FilterFormatInterface $filter_format) {
  self::checkCsrf($request, \Drupal::currentUser());

  $text = $request->query->get('text');
  $uuid = $request->query->get('uuid');
  if ($text == '' || $uuid == '') {
    throw new NotFoundHttpException();
  }

  $build = [
    '#type' => 'processed_text',
    '#text' => $text,
    '#format' => $filter_format->id(),
  ];
  $html = $this->renderer->renderInIsolation($build);

  $headers = [];
  if ($media = $this->entityRepository->loadEntityByUuid('media', $uuid)) {
    $headers['Drupal-Media-Label'] = $this->entityRepository->getTranslationFromContext($media)->label();
  }

Steps to reproduce

Proposed resolution

Add view label access check

Remaining tasks

Needs review

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3593390

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

larowlan created an issue. See original summary.

larowlan’s picture

Issue tags: +Needs tests

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

mohit_aghera’s picture

Status: Active » Needs review
Issue tags: -Needs tests

Code changes are already pushed by @larowlan
Added tests.
Tests are green and test-only job fails as expected.

mohit_aghera’s picture

Issue summary: View changes
larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me, going to mark it as RTBC even though I pushed the fix - because that was only trivial

  • catch committed 283638ec on 10.6.x
    fix: #3593390 Media Preview Endpoint Leaks Labels Of Non-Viewable Media...

  • catch committed fc1df9b8 on 11.4.x
    fix: #3593390 Media Preview Endpoint Leaks Labels Of Non-Viewable Media...

  • catch committed 75e27991 on 11.x
    fix: #3593390 Media Preview Endpoint Leaks Labels Of Non-Viewable Media...

  • catch committed 6ce4beea on main
    fix: #3593390 Media Preview Endpoint Leaks Labels Of Non-Viewable Media...
catch’s picture

Version: main » 10.6.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to main and cherry-picked to 11.x, 11.4.x and 10.6.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • catch committed 60f97da2 on 10.6.x
    Revert "fix: #3593390 Media Preview Endpoint Leaks Labels Of Non-...
catch’s picture

Status: Fixed » Patch (to be ported)

Had to revert the 10.6.x commit due to phpunit attributes etc. Moving to 'to be ported'.

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

smustgrave’s picture

Status: Patch (to be ported) » Needs review

Opened a 10.6.x branch.

smustgrave’s picture

Status: Needs review » Needs work

Actually drupalGet hasn't been backported so question is do we convert to functional test on 10.6.x, postpone this, or what?

mohit_aghera’s picture

Status: Needs work » Needs review

All the blockers related 10.6.x are merged and PR is updated with latest 10.6.x.
I noticed a few failures and those have been fixed.
Good to get another round of review.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

THanks @mohit_aghera looks like a good backport to me!

  • larowlan committed c6cc68a2 on 10.6.x
    fix: #3593390 Media Preview Endpoint Leaks Labels Of Non-Viewable Media...

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 10.6.x - thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.