From 1bf5aac7c6b14ae0d45526eec529f3efa62c4aad Mon Sep 17 00:00:00 2001 From: Marco Rieser Date: Sun, 22 Dec 2024 16:13:30 +0100 Subject: [PATCH] Use base64url helpers in glide --- src/Http/Controllers/GlideController.php | 4 ++-- src/Imaging/GlideUrlBuilder.php | 8 ++++---- src/Imaging/ImageGenerator.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Http/Controllers/GlideController.php b/src/Http/Controllers/GlideController.php index 88ec39e24d..61489a5fe2 100644 --- a/src/Http/Controllers/GlideController.php +++ b/src/Http/Controllers/GlideController.php @@ -73,7 +73,7 @@ public function generateByUrl($url) { $this->validateSignature(); - $url = base64_decode($url); + $url = Str::fromBase64Url($url); return $this->createResponse($this->generateBy('url', $url)); } @@ -90,7 +90,7 @@ public function generateByAsset($encoded) { $this->validateSignature(); - $decoded = base64_decode($encoded); + $decoded = Str::fromBase64Url($encoded); // The string before the first slash is the container [$container, $path] = explode('/', $decoded, 2); diff --git a/src/Imaging/GlideUrlBuilder.php b/src/Imaging/GlideUrlBuilder.php index 8bfdf2c325..5b34bf9e1d 100644 --- a/src/Imaging/GlideUrlBuilder.php +++ b/src/Imaging/GlideUrlBuilder.php @@ -36,15 +36,15 @@ public function build($item, $params) switch ($this->itemType()) { case 'url': - $path = 'http/'.base64_encode($item); + $path = 'http/'.Str::toBase64Url($item); $filename = Str::afterLast($item, '/'); break; case 'asset': - $path = 'asset/'.base64_encode($this->item->containerId().'/'.$this->item->path()); + $path = 'asset/'.Str::toBase64Url($this->item->containerId().'/'.$this->item->path()); $filename = Str::afterLast($this->item->path(), '/'); break; case 'id': - $path = 'asset/'.base64_encode(str_replace('::', '/', $this->item)); + $path = 'asset/'.Str::toBase64Url(str_replace('::', '/', $this->item)); break; case 'path': $path = URL::encode($this->item); @@ -61,7 +61,7 @@ public function build($item, $params) if (isset($params['mark']) && $params['mark'] instanceof Asset) { $asset = $params['mark']; - $params['mark'] = 'asset::'.base64_encode($asset->containerId().'/'.$asset->path()); + $params['mark'] = 'asset::'.Str::toBase64Url($asset->containerId().'/'.$asset->path()); } return URL::prependSiteRoot($builder->getUrl($path, $params)); diff --git a/src/Imaging/ImageGenerator.php b/src/Imaging/ImageGenerator.php index cb44c6dde7..49273a9e72 100644 --- a/src/Imaging/ImageGenerator.php +++ b/src/Imaging/ImageGenerator.php @@ -199,7 +199,7 @@ private function setUpWatermark($watermark): string private function getWatermarkFilesystemAndParam($item) { if (is_string($item) && Str::startsWith($item, 'asset::')) { - $decoded = base64_decode(Str::after($item, 'asset::')); + $decoded = Str::fromBase64Url(Str::after($item, 'asset::')); [$container, $path] = explode('/', $decoded, 2); $item = Assets::find($container.'::'.$path); }