From a1245c74cc817d3abde94c1045d92ccfe07542f9 Mon Sep 17 00:00:00 2001 From: Marc Willmann Date: Wed, 18 Nov 2026 15:53:20 +0100 Subject: [PATCH] [BUGFIX] Skip fallback if the static file vanishes while reading it The fallback middleware checks that the static file exists and reads it afterwards. If the file is removed in between (e.g. by a cache flush), GeneralUtility::getUrl() returns false and HtmlResponse throws a TypeError. A failed read is now handled like a missing static file, so the request is passed on to TYPO3. Co-Authored-By: Claude Opus 5.5 --- Classes/Middleware/FallbackMiddleware.php | 8 +++++++- Tests/Unit/Middleware/FallbackMiddlewareTest.php | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Classes/Middleware/FallbackMiddleware.php b/Classes/Middleware/FallbackMiddleware.php index 4ae71417036..f8f3e78ab7b 100644 --- a/Classes/Middleware/FallbackMiddleware.php +++ b/Classes/Middleware/FallbackMiddleware.php @@ -80,7 +80,13 @@ protected function handleViaFallback(ServerRequestInterface $request): ResponseI throw new Exception('The path is not in the cache directory', 348923472); } - return new HtmlResponse(GeneralUtility::getUrl($possibleStaticFile), 200, $headers); + // The file might be removed (e.g. by a cache flush) after the checks above + $content = GeneralUtility::getUrl($possibleStaticFile); + if (false === $content) { + throw new Exception('StaticFileCache file could not be read', 1795530268); + } + + return new HtmlResponse($content, 200, $headers); } /** diff --git a/Tests/Unit/Middleware/FallbackMiddlewareTest.php b/Tests/Unit/Middleware/FallbackMiddlewareTest.php index 826febd4bc2..fc5f2798417 100644 --- a/Tests/Unit/Middleware/FallbackMiddlewareTest.php +++ b/Tests/Unit/Middleware/FallbackMiddlewareTest.php @@ -222,6 +222,22 @@ public function testMissingStaticFileSkipsFallback(): void $this->assertHandledByTypo3($this->getMiddleware()); } + public function testStaticFileRemovedWhileReadingSkipsFallback(): void + { + file_put_contents($this->staticFile, 'cached'); + + // The cache directory is requested after the file checks and before the file is read: + // remove the file at this point, like a concurrent cache flush would do. + $this->cacheService = $this->createStub(CacheService::class); + $this->cacheService->method('getAbsoluteBaseDirectory')->willReturnCallback(function (): string { + unlink($this->staticFile); + + return $this->cacheDirectory; + }); + + $this->assertHandledByTypo3($this->getMiddleware()); + } + public function testFileOutsideOfCacheDirectorySkipsFallback(): void { file_put_contents($this->staticFile, 'cached');