Problem/Motivation

For image style derivatives,
FlysystemStreamWrapper::getExternalUrl() routes the URL back
through Drupal:

$dir_path = $this->getPublicDirectoryPath();
if ($dir_path !== NULL) {
  $base = rtrim($this->getDrupalBaseUrl(), '/');
  return $base . '/' . $dir_path . '/' . $target;
}

The NULL check is not enough: getPublicDirectoryPath() returns
'' (not NULL) when the public scheme's
public_url_base has no path component — a bare CDN or bucket
domain. The result contains a double slash:
https://example.com//styles/large/public/foo.jpg.

Once file_url_transform_relative() strips the base off, the
markup contains //styles/large/public/foo.jpg, which browsers
parse as protocol-relative: the host becomes styles and the image
never loads.

This affects both branches that build a Drupal-routed derivative URL (the
CloudFront branch and the generic non-local adapter branch).

Steps to reproduce

  1. Configure a Flysystem scheme whose public_url_base is a bare
    domain (no path), used for public://.
  2. Render any image with an image style.
  3. Inspect the markup: src="//styles/...", image 404s / resolves
    against the wrong host.

Proposed resolution

Only insert the directory path segment when it is non-empty:

return $dir_path !== ''
  ? $base . '/' . $dir_path . '/' . $target
  : $base . '/' . $target;

Remaining tasks

  • Review.
  • Unit coverage in FlysystemStreamWrapperTest with
    getPublicDirectoryPath() returning ''.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork flysystem-3616491

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

luigisa created an issue. See original summary.

lisa.rae made their first commit to this issue’s fork.

lisa.rae’s picture

Postponing any review of the MR on this issue pending review and acceptance of the MR on the related issue, https://www.drupal.org/project/flysystem/issues/3616488

lisa.rae’s picture

Status: Postponed » Needs review
luigisa’s picture

Status: Needs review » Closed (duplicate)

Closing as duplicate of #3616488.

The empty public-directory-path guard in FlysystemStreamWrapper::getExternalUrl()
(and the matching unit tests) already landed in 3.0.x via 3e8d16a as part of
that issue. Rebasing this MR onto current 3.0.x leaves an empty diff.

MR !120 can be closed without merging.

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.

lisa.rae’s picture

Thank you!