"Restrict images to this site" blocks image style derivatives

Created on 7 July 2015, over 9 years ago
Updated 22 November 2023, about 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 5 days 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

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States ericras

    Reroll for 10.1

  • last update over 1 year ago
    29,465 pass
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    In case anyone else runs into a similar problem - a site was showing a symptom like this, only the problem turned out to be a custom URL processor that was changing all image paths of a certain type from "public" to "private", regardless of where the source image was. After far too much time was spent digging through the problem, removing the few lines of custom code fixed it and the images loaded again. X-|

Production build 0.71.5 2024