Problem/Motivation

According to instructions of comments in settings.php, a different domain can be set in the public file base URL ($settings['file_public_base_url']), which allows the serving of static files to a CDN service.

After enable that setting, inline images uploaded with CKEditor will have an absolute URL in the src attribute. That works as expected. But with the "Restrict images to this site" filter enabled, all uploaded images will fail to display because their src attributes won't start with $base_path anymore.

Steps to reproduce

  1. Install Drupal.
  2. Setup a web server (like nginx or caddy) to handle TLS access to the site's domain, let's say, "https://mysite.com" for example.)
  3. Setup $settings['file_public_base_url'] to an external domain, let's say "https://files.mysite.com", also setup my web server to serve file from Drupal's files folder under that domain.
  4. Enable modules like CKEditor, create a text format with CKEditor and inline-images uploads enabled.
  5. Enable "Restrict images to this site" filter.
  6. Add an article with inline-images. These images look fine in the CKEditor, but fail to display after I publish the article.

Proposed resolution

While checking function in filter.module checks only whether or not the src attribute starts with $base_path, and whether or not the file is reachable (by running getimagesize()), I think the function should check the src attribute in a detailed manner, to make sure the filter can work with other functions of Drupal like public file base URL (or maybe image styles or so).

CommentFileSizeAuthor
#6 3201331-06.patch1.15 KBhehongbo
#2 identify_public_base_url.patch1019 byteshehongbo

Comments

hehongbo created an issue. See original summary.

hehongbo’s picture

StatusFileSize
new1019 bytes

Came up with this dirty patch as a workaround, but I don't know if it's a good idea, since this also bypasses the file existence check.

hehongbo’s picture

hehongbo’s picture

StatusFileSize
new1.22 KB

Sorry for my bad habits as I'm new in PHP coding/debugging. The namespaced class are referenced with use statements in this one as the CI suggests.

hehongbo’s picture

StatusFileSize
new1.22 KB
hehongbo’s picture

StatusFileSize
new1.15 KB

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

hehongbo’s picture

Status: Active » Needs work

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

socialnicheguru’s picture

When installing a site and even some modules i get this: Passing null to parameter #1 ($string) of type string is deprecated filter.module

The variable is not set yet on install:

$public_base_url = Settings::get("file_public_base_url");
$public_base_url_length = mb_strlen($public_base_url);

Drupal 10.4.8
php8.3

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.