Media Library: buildInputElement on media library content view does not return the correct form element

Created on 2 May 2024, 12 months ago

This issue was reported privately but has been approved for public discussion by the Drupal Security Team.

Problem/Motivation

In testing use of the Media Library from the form widget on the Node Edit form, we have discovered that the buildInputElement function used to create the file upload form element is not returning the correct upload element. Notably on an image field, it is returning the standard file_managed_file element rather than the image_widget.
This bypasses the verification of the uploaded files as actual images, resulting in a security issue as it allows any file type to be uploaded as long as the file extension is on the allowed list. These validators such as file_validate_is_image are not called during the entire media entity creation process via Media Library. This allows for potentially problematic files that would otherwise not be able to be uploaded to bypass normal checks.
Secondly this element is hard-coded to have “#multiple” as TRUE even if the source field is limited to one item, allowing multiple files to be uploaded if selected from the system-level file open dialog, as long as they are below the size limit. These files are staged into the sites/files directory, and temporary managed file entities created for them, though no media entities are, only one for the last file uploaded . This allows for “shadow” files to be uploaded for a short time.

Steps to reproduce

  1. Add Entity Reference field type onto a node, set to use a media type such as “image” that has an Image or other restricted file type field
  2. Set to use the “Media Library” form display
  3. Create node and add content using the Media Library form.
  4. upload a non-compliant file renamed with an acceptable file extension. Also select multiple files in the file selection system dialog.

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Media 

Last updated about 3 hours ago

Created by

🇦🇺Australia mingsong 🇦🇺

Live updates comments and jobs are added and updated live.
  • Security improvements

    It makes Drupal less vulnerable to abuse or misuse. Note, this is the preferred tag, though the Security tag has a large body of issues tagged to it. Do NOT publicly disclose security vulnerabilities; contact the security team instead. Anyone (whether security team or not) can apply this tag to security improvements that do not directly present a vulnerability e.g. hardening an API to add filtering to reduce a common mistake in contributed modules.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024