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
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
Comment #3
larowlanComment #5
mohit_aghera commentedCode changes are already pushed by @larowlan
Added tests.
Tests are green and test-only job fails as expected.
Comment #6
mohit_aghera commentedComment #7
larowlanLooks good to me, going to mark it as RTBC even though I pushed the fix - because that was only trivial
Comment #12
catchCommitted/pushed to main and cherry-picked to 11.x, 11.4.x and 10.6.x, thanks!
Comment #16
catchHad to revert the 10.6.x commit due to phpunit attributes etc. Moving to 'to be ported'.
Comment #18
smustgrave commentedOpened a 10.6.x branch.
Comment #20
smustgrave commentedActually drupalGet hasn't been backported so question is do we convert to functional test on 10.6.x, postpone this, or what?
Comment #21
mohit_aghera commentedAll 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.
Comment #22
smustgrave commentedTHanks @mohit_aghera looks like a good backport to me!
Comment #25
larowlanCommitted to 10.6.x - thanks!