Merge remote-tracking branch 'origin/feature/HOR-3559' into feature/HOR-3629
This commit is contained in:
@@ -152,6 +152,11 @@ class pmTables extends Controller
|
||||
$sFileName = $httpData->f;
|
||||
|
||||
$realPath = $PUBLIC_ROOT_PATH . $sFileName;
|
||||
|
||||
if ($this->isValidFileToBeStreamed($sFileName) === false) {
|
||||
throw new Exception("You are trying to access an unauthorized resource.");
|
||||
}
|
||||
|
||||
G::streamFile( $realPath, true );
|
||||
unlink( $realPath );
|
||||
}
|
||||
@@ -206,5 +211,32 @@ class pmTables extends Controller
|
||||
$tableSize = $tableSize - 8; // Prefix PMT_
|
||||
return $tableSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates if the file with the $fileName is a valid one,
|
||||
* that is, it must be a file without relative references that
|
||||
* can open a door to get some unauthorized system file and
|
||||
* must have one of the valid file extensions.
|
||||
*
|
||||
* @param $fileName, emporal file name that will be streamed
|
||||
* @return bool
|
||||
*/
|
||||
private function isValidFileToBeStreamed($fileName)
|
||||
{
|
||||
$result = true;
|
||||
$validExtensionsForExporting = ['csv', 'pmt'];
|
||||
|
||||
$pathInfo = pathinfo($fileName);
|
||||
|
||||
if ($pathInfo['dirname'] !== '.') {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if (!in_array($pathInfo['extension'], $validExtensionsForExporting)) {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user