static/img: Make sure to correctly access module images

fixes #4226
This commit is contained in:
Johannes Meyer 2020-08-14 11:46:19 +02:00
parent 250ae929dd
commit 3035efac65

View File

@ -68,16 +68,16 @@ class StaticController extends Controller
*/ */
public function imgAction() public function imgAction()
{ {
$moduleRoot = Icinga::app() $imgRoot = Icinga::app()
->getModuleManager() ->getModuleManager()
->getModule($this->getParam('module_name')) ->getModule($this->getParam('module_name'))
->getBaseDir(); ->getBaseDir() . '/public/img/';
$file = $this->getParam('file'); $file = $this->getParam('file');
$filePath = realpath($moduleRoot . '/public/img/' . $file); $filePath = realpath($imgRoot . $file);
if ($filePath === false) { if ($filePath === false || substr($filePath, 0, strlen($imgRoot)) !== $imgRoot) {
$this->httpNotFound('%s does not exist', $filePath); $this->httpNotFound('%s does not exist', $file);
} }
if (preg_match('/\.([a-z]+)$/i', $file, $m)) { if (preg_match('/\.([a-z]+)$/i', $file, $m)) {