Only serve existing static library assets, really!?

This commit is contained in:
Johannes Meyer 2022-02-23 17:18:16 +01:00
parent 52d51f0ee5
commit 379ddb91f0
1 changed files with 14 additions and 3 deletions

View File

@ -39,10 +39,21 @@ class StaticController
}
$assetRoot = $library->getStaticAssetPath();
$filePath = $assetRoot . DIRECTORY_SEPARATOR . $assetPath;
if (empty($assetRoot)) {
$app->getResponse()
->setHttpResponseCode(404);
// Doesn't use realpath as it isn't supposed to access files outside asset/static
if (! is_readable($filePath) || ! is_file($filePath)) {
return;
}
$filePath = $assetRoot . DIRECTORY_SEPARATOR . $assetPath;
$dirPath = realpath(dirname($filePath)); // dirname, because the file may be a link
if (
$dirPath === false
|| substr($dirPath, 0, strlen($assetRoot)) !== $assetRoot
|| ! is_file($filePath)
) {
$app->getResponse()
->setHttpResponseCode(404);