From 375c1ceb7d8422c84dd04d4cbde1930c35c993c9 Mon Sep 17 00:00:00 2001 From: Ivo Valchev Date: Fri, 30 Jul 2021 13:38:27 +0200 Subject: [PATCH] Throw 404 response when thumbnailing a missing image --- src/Controller/ImageController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Controller/ImageController.php b/src/Controller/ImageController.php index e560c5e95..6e49823e9 100644 --- a/src/Controller/ImageController.php +++ b/src/Controller/ImageController.php @@ -115,10 +115,14 @@ private function buildImage(string $filename): string private function buildResponse(string $filename): Response { + $filepath = $this->getPath(null, false, $filename); + + if (! (new Filesystem())->exists($filepath)) { + throw new NotFoundHttpException(sprintf("The file '%s' does not exist.", $filepath)); + } + // In case we're trying to "thumbnail" an svg, just return the whole thing. if ($this->isSvg($filename)) { - $filepath = sprintf('%s%s%s', $this->getPath(), DIRECTORY_SEPARATOR, $filename); - $response = new Response(file_get_contents($filepath)); $response->headers->set('Content-Type', 'image/svg+xml');