From b17b2ccc3944a57fc871bee38f9620b90d1d0cee Mon Sep 17 00:00:00 2001 From: Wilfried Wolf Date: Thu, 21 Nov 2024 17:47:50 +0100 Subject: [PATCH 1/2] Update UrlConvertor.php to solve --- Util/UrlConvertor.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Util/UrlConvertor.php b/Util/UrlConvertor.php index aec5e5a..2078e7a 100644 --- a/Util/UrlConvertor.php +++ b/Util/UrlConvertor.php @@ -86,22 +86,28 @@ public function isLocal(string $url): bool public function getUrlFromFilename(string $filename): string { try { - if (strpos($filename, $this->getMediaFolder()) !== false) { - return str_replace($this->getMediaFolder() . '/', $this->getMediaUrl(), $filename); + $mediaFolder = $this->getMediaFolder(); + $realMediaFolder = realpath($mediaFolder); + if (str_contains($filename, $realMediaFolder)) { + return str_replace($mediaFolder . '/', $this->getMediaUrl(), $filename); } } catch (FileSystemException|NoSuchEntityException $e) { throw new NotFoundException((string)__('Media folder does not exist')); } try { - if (strpos($filename, $this->getStaticFolder()) !== false) { + $staticFolder = $this->getStaticFolder(); + $realStaticFolder = realpath($staticFolder); + if (strpos($filename, $realStaticFolder) !== false) { return str_replace($this->getStaticFolder() . '/', $this->getStaticUrl(), $filename); } } catch (FileSystemException|NoSuchEntityException $e) { throw new NotFoundException((string)__('Static folder does not exist')); } - if (strpos($filename, $this->getBaseFolder()) !== false) { + $baseFolder = $this->getBaseFolder(); + $realBaseFolder = realpath($baseFolder); + if (strpos($filename, $realBaseFolder) !== false) { return str_replace($this->getBaseFolder() . '/', $this->getBaseUrl(), $filename); } From 838794b173631762590728bdfb9deb6ab8abe256 Mon Sep 17 00:00:00 2001 From: Wilfried Wolf Date: Thu, 21 Nov 2024 17:52:51 +0100 Subject: [PATCH 2/2] Uses real directory path to allow symlinks --- Util/UrlConvertor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Util/UrlConvertor.php b/Util/UrlConvertor.php index 2078e7a..881ab69 100644 --- a/Util/UrlConvertor.php +++ b/Util/UrlConvertor.php @@ -98,7 +98,7 @@ public function getUrlFromFilename(string $filename): string try { $staticFolder = $this->getStaticFolder(); $realStaticFolder = realpath($staticFolder); - if (strpos($filename, $realStaticFolder) !== false) { + if (str_contains($filename, $realStaticFolder)) { return str_replace($this->getStaticFolder() . '/', $this->getStaticUrl(), $filename); } } catch (FileSystemException|NoSuchEntityException $e) { @@ -107,7 +107,7 @@ public function getUrlFromFilename(string $filename): string $baseFolder = $this->getBaseFolder(); $realBaseFolder = realpath($baseFolder); - if (strpos($filename, $realBaseFolder) !== false) { + if (str_contains($filename, $realBaseFolder)) { return str_replace($this->getBaseFolder() . '/', $this->getBaseUrl(), $filename); }