sec: better path sanitization
Signed-off-by: Varun Patil <varunpatil@ucla.edu>pull/579/head
parent
c25dd6e640
commit
83be3c93b1
|
@ -134,7 +134,7 @@ class ArchiveController extends GenericApiController
|
|||
} else {
|
||||
// file not in archive, put it in there
|
||||
$af = \OCA\Memories\Util::$ARCHIVE_FOLDER;
|
||||
$destinationPath = Exif::removeExtraSlash($af.$relativeFilePath);
|
||||
$destinationPath = Exif::sanitizePath($af.$relativeFilePath);
|
||||
}
|
||||
|
||||
// Remove the filename
|
||||
|
|
|
@ -103,13 +103,13 @@ class FsManager
|
|||
|
||||
try {
|
||||
if (null !== $folderPath) {
|
||||
$folder = $userFolder->get(Exif::removeExtraSlash($folderPath));
|
||||
$folder = $userFolder->get(Exif::sanitizePath($folderPath));
|
||||
$root->addFolder($folder);
|
||||
} else {
|
||||
// Get timeline paths
|
||||
$paths = Exif::getTimelinePaths($uid);
|
||||
if ($path = $this->request->getParam('timelinePath', null)) {
|
||||
$paths = [Exif::removeExtraSlash($path)];
|
||||
$paths = [Exif::sanitizePath($path)];
|
||||
}
|
||||
|
||||
// Combined etag, for cache invalidation.
|
||||
|
|
12
lib/Exif.php
12
lib/Exif.php
|
@ -81,15 +81,9 @@ class Exif
|
|||
*/
|
||||
public static function sanitizePath(string $path)
|
||||
{
|
||||
return mb_ereg_replace('([^\\w\\s\\d\\-_~,;:!@#$&*{}\[\]\'\\[\\]\\(\\).\\\/])', '', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep only one slash if multiple repeating.
|
||||
*/
|
||||
public static function removeExtraSlash(string $path)
|
||||
{
|
||||
return mb_ereg_replace('\/\/+', '/', $path);
|
||||
$path = mb_ereg_replace('([^\\w\\s\\d\\-_~,;:!@#$&*{}\[\]\'\\[\\]\\(\\).\\\/])', '', $path);
|
||||
$path = mb_ereg_replace('\/\/+', '/', $path); // remove extra slashes
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue