SecurityFileUploadEventSubscriber.php regex is too broad.

Created on 20 June 2025, 3 days ago

Problem/Motivation

Uploading files that have '.' characters in the name can sometimes trigger the renaming in the sanitizeName function of the FileUploadSanitizeNameEvent.

This is happening because the regex is assuming that anything after the first '.' character is an extension and does not allow for patterns that are 2-5 letters long and optionally followed by a digit.

Steps to reproduce

1. Go to /media/add/image
2. Upload a file with the name "test.image.jpg"
3. Verify the "For security reasons, your upload has been renamed to..." message appears
4. Upload a file with the name "test.images.jpg"
5. Verify the image we uploaded successfully.

Proposed resolution

in `web/core/modules/system/src/EventSubscriber/SecurityFileUploadEventSubscriber.php` change:

elseif (!empty($extensions) && !in_array(strtolower($filename_part), $extensions) && preg_match("/^[a-zA-Z]{2,5}\d?$/", $filename_part)) {

To:

elseif (!empty($extensions) && !in_array(strtolower($filename_part), $extensions) && in_array(strtolower($filename_part), FileSystemInterface::INSECURE_EXTENSIONS, TRUE)) {

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.1 πŸ”₯

Component

file system

Created by

πŸ‡ΊπŸ‡ΈUnited States vetchneons

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024