Skip to content

Commit

Permalink
Fixed issue [security] #15848: Check that filename is not changed bef…
Browse files Browse the repository at this point in the history
…ore moving/copying
  • Loading branch information
olleharstedt committed Feb 12, 2020
1 parent e324f82 commit b6c1d1b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions application/controllers/admin/LimeSurveyFileManager.php
Expand Up @@ -198,6 +198,8 @@ public function transitFiles()
$checkDirectory = $this->_checkFolder($folder, $iSurveyId);

foreach($files as $file) {
$this->checkChangedFilename($file);

$realTargetPath = dirname(Yii::app()->basePath) . DIRECTORY_SEPARATOR . $folder;
$fileDestination = realpath($realTargetPath) . DIRECTORY_SEPARATOR . $file['shortName'];

Expand Down Expand Up @@ -740,6 +742,29 @@ private function throwError()
0
);
}

/**
* Throw exception if src and dest filename is different.
*
* @param array $file
* @return void
* @throws \Exception
*/
private function checkChangedFilename(array $file)
{
/** @var string[] */
$pathParts = explode('/', $file['path']);
/** @var string */
$lastPart = $pathParts[count($pathParts) - 1];

if ($lastPart !== $file['shortName']) {
$this->_setError(
"FILENAME_CHANGED",
gT("The destination file name is not the same as the source file name")
);
$this->throwError();
}
}
}

class FileManagerError
Expand Down

0 comments on commit b6c1d1b

Please sign in to comment.