Problem/Motivation

In the latest release 3.0.8 my image fields that are configured to accept only specific file types now allow to upload files using extensions that are not in the allowed list.

Steps to reproduce

  1. Create an image field with the following settings:
    • Upload destination: Rokka
    • Allowed file extensions: "jpg jpeg"
  2. Use the entity create form to upload an image to the field.

Expected result: I can only upload images with the extensions jpg or jpeg.
Actual result: I can upload images with extensions jpg, jpeg, pdf, eps, webp, svg, tiff, heic.

Proposed resolution

Don't change the configured file extensions.

Issue fork rokka-3461515

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

pfrenssen created an issue. See original summary.

pfrenssen’s picture

Status: Active » Needs review
ayalon’s picture

It was like that before. But for all image fields. Now it is limited to rokka fields.

pfrenssen’s picture

Standard image field when using Rokka 3.0.6:

After updating to Rokka 3.0.8:

The regression has been introduced in commit: 5387a5f.

The previous implementation was extending the allowed extensions in RokkaImageFactory::getSupportedExtensions() which was OK since the image factory needs to know which extensions it can handle. This does not affect user facing forms in any way.

In the commit the extensions that are supported by Rokka but not by the default GD2 image library are being injected in user facing forms:

function rokka_field_widget_single_element_form_alter(&$element, FormStateInterface $form_state, $context) {
  // ...
  if ($uri_schema === 'rokka') {
    $default = explode(' ', $element['#upload_validators']['FileExtension']['extensions']);
    $rokka_specific = ['pdf', 'eps', 'webp', 'svg', 'tiff', 'heic'];
    $extensions = array_unique(array_merge($default, $rokka_specific), SORT_REGULAR);
    $element['#upload_validators']['FileExtension']['extensions'] = implode(' ', $extensions);
  }
}

There is no need to append the extensions in this way. The File module already allows the site builder to set the allowed extensions using the Field UI. They can just add PDF or other extensions there.

From a different perspective: the file extensions that can be stored on Rokka should not be controlled on form level, but rather by the image manipulation API. Then they will work correctly also when files are added outside of forms. We should use ImageToolkitInterface::getSupportedExtensions(), as is proposed as part of the fix for #3461471: Fatal error "Stream must be a resource".

  • pfrenssen committed 4b0ff914 on 3.x
    feat: #3461515 Image widgets allow to upload unwanted file types (eg PDF...
pfrenssen’s picture

Status: Needs review » Fixed

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.

Status: Fixed » Closed (fixed)

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