Problem/Motivation

docker-compose.yml
version: '3'

services:
drupal:
image: drupal
ports:
- 80:80
db:
image: mariadb
environment:
MYSQL_DATABASE: drupal
MYSQL_ROOT_PASSWORD: password

composer require drush/drush
composer require 'drupal/imce:^3.0'
drush en imce

http://localhost/admin/imce/browser
Uploaded aa.docx.

The following message is displayed and cannot upload.

The specified file aa.docx could not be uploaded.
Only files with the following extensions are allowed: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp.

I was able to upload aa.doc.

drush pmu imce
composer remove drupal/imce
composer require 'drupal/imce:3.0.9'
drush en imce

I can upload aa.docx

/admin/config/media/imce/admin?destination=/admin/config/media/imce

Allowed file extensions is *.

Drupal 10.1.7
PHP 8.2.14

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#5 3411471-1538125.patch579 bytesytsuhako

Comments

ytsuhako created an issue. See original summary.

ytsuhako’s picture

I can upload if I type docx instead of asterisks in the allowed extensions.

j_s’s picture

I'm getting the same error with the asterisk meant to allow all file types on 3.0.10. Setting a specific list of file types does work at least.

ytsuhako’s picture

/opt/drupal/web/modules/contrib/imce/src/Plugin/ImcePlugin/Upload.php

    if ($exts !== '*') {
      $validators['file_validate_extensions'] = [$exts];
    } 

It worked when changed to the following.

    if ($exts !== '*') {
      $validators['file_validate_extensions'] = [$exts];
    } else {
      $validators['file_validate_extensions'] = [Null];
    }

I made this change because it is handled as follows in the core.

/opt/drupal/web/core/modules/file/src/Upload/FileUploadHandler.php

  protected function handleExtensionValidation(array &$validators): string {
    // Build a list of allowed extensions.
    if (isset($validators['file_validate_extensions'])) {
      if (!isset($validators['file_validate_extensions'][0])) {
        // If 'file_validate_extensions' is set and the list is empty then the
        // caller wants to allow any extension. In this case we have to remove the
        // validator or else it will reject all extensions.
        unset($validators['file_validate_extensions']);
      }
    }
    else {
      // No validator was provided, so add one using the default list.
      // Build a default non-munged safe list for
      // \Drupal\system\EventSubscriber\SecurityFileUploadEventSubscriber::sanitizeName().
      $validators['file_validate_extensions'] = [self::DEFAULT_EXTENSIONS];
    }
    return $validators['file_validate_extensions'][0] ?? '';
  }
ytsuhako’s picture

StatusFileSize
new579 bytes

  • ufku committed cc511420 on 3.x
    Issue #3411471: Fix file validation not allowing all extensions.
    
    Use...
ufku’s picture

Version: 3.0.10 » 3.x-dev
Status: Active » Fixed

Fixed in 3.0.11
Thanks for reporting.

ytsuhako’s picture

Problem solved for me.
Thanks a lot.

j_s’s picture

All fixed for me! Thanks!

Status: Fixed » Closed (fixed)

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

jeff.a’s picture

Not sure if this one is fixed... still have the issue after updating to 3.0.12 and core 10.2.7.

I am able to upload files when I put a wildcard (*) in the "Allowed file extensions" field, but I'm still getting the error when I limit to certain extensions.