Skip to content

Commit

Permalink
Merge commit from fork
Browse files Browse the repository at this point in the history
* Check if path is mounted in FileSelector

* Use Path::isBasePath()

Co-authored-by: Fritz Michael Gschwantner <fmg@inspiredminds.at>

* Coding style

Co-authored-by: Leo Feyer <1192057+leofeyer@users.noreply.github.com>

---------

Co-authored-by: Fritz Michael Gschwantner <fmg@inspiredminds.at>
Co-authored-by: Leo Feyer <1192057+leofeyer@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent c9a3a3c commit 63409c6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions core-bundle/src/Resources/contao/widgets/FileSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ public function generateAjax($strFolder, $strField, $level, $mount=false)
*/
protected function renderFiletree($path, $intMargin, $mount=false, $blnProtected=true, $arrFound=array())
{
if (!$this->isMounted($path))
{
throw new \RuntimeException('Folder "' . $path . '" is not mounted or cannot be found.');
}

// Invalid path
if (!is_dir($path))
{
Expand Down Expand Up @@ -665,6 +670,38 @@ protected function isProtectedPath($path)

return true;
}

protected function isMounted($path)
{
if (Validator::isInsecurePath($path))
{
throw new \RuntimeException('Insecure path ' . $path);
}

$this->import(BackendUser::class, 'User');

$path = StringUtil::stripRootDir($path);
$filemounts = array();

if ($this->User->isAdmin)
{
$filemounts[] = System::getContainer()->getParameter('contao.upload_path');
}
elseif (\is_array($this->User->filemounts))
{
$filemounts = $this->User->filemounts;
}

foreach ($filemounts as $filemount)
{
if (Path::isBasePath($filemount, $path))
{
return true;
}
}

return false;
}
}

class_alias(FileSelector::class, 'FileSelector');

0 comments on commit 63409c6

Please sign in to comment.