"Restrict images to this site" blocks image style derivatives

Created on 7 July 2015, over 9 years ago
Updated 10 August 2023, over 1 year ago

Problem/Motivation

The filter checks if an image is local by trying to load image dimensions from the local file, if that fails, the image is marked as remote and removed from the markup:

      // Ensure the path refers to an actual image by prefixing the image source
      // with the Drupal root and running getimagesize() on it.
      $local_image_path = $local_dir . Unicode::substr($src, $base_path_length);
      $local_image_path = rawurldecode($local_image_path);
      if (@getimagesize($local_image_path)) {
        // The image has the right path. Erroneous images are dealt with below.
        continue;
      }

That code breaks for private:// files, because the image URL looks something like /system/files/inline-images/search.jpg, but that directory does not exist on disk.

It also breaks when using image style derivatives (particularly an issue when using a module like entity embed). The URL to the image includes a token as a query parameter, and this token is still present when checking for the file on the file system.

Proposed resolution

TBD

Remaining tasks

TBD

User interface changes

None. (Well, working private images.)

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Needs work

Version

9.5

Component
FilterΒ  β†’

Last updated about 19 hours ago

No maintainer
Created by

πŸ‡¨πŸ‡­Switzerland floretan

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024