Merge pull request #21484 from nextcloud/better-forbidden-path-errors
show better error messages when a file with a forbidden path is encountered
This commit is contained in:
commit
ad16b19ec7
|
@ -288,16 +288,14 @@ class Local extends \OC\Files\Storage\Common {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function treeContainsBlacklistedFile(string $path): bool {
|
private function checkTreeForForbiddenItems(string $path) {
|
||||||
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
|
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
|
||||||
foreach ($iterator as $file) {
|
foreach ($iterator as $file) {
|
||||||
/** @var \SplFileInfo $file */
|
/** @var \SplFileInfo $file */
|
||||||
if (Filesystem::isFileBlacklisted($file->getBasename())) {
|
if (Filesystem::isFileBlacklisted($file->getBasename())) {
|
||||||
return true;
|
throw new ForbiddenException('Invalid path: ' . $file->getPathname(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rename($path1, $path2) {
|
public function rename($path1, $path2) {
|
||||||
|
@ -337,9 +335,7 @@ class Local extends \OC\Files\Storage\Common {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->treeContainsBlacklistedFile($this->getSourcePath($path1))) {
|
$this->checkTreeForForbiddenItems($this->getSourcePath($path1));
|
||||||
throw new ForbiddenException('Invalid path', false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rename($this->getSourcePath($path1), $this->getSourcePath($path2));
|
return rename($this->getSourcePath($path1), $this->getSourcePath($path2));
|
||||||
|
@ -437,7 +433,7 @@ class Local extends \OC\Files\Storage\Common {
|
||||||
*/
|
*/
|
||||||
public function getSourcePath($path) {
|
public function getSourcePath($path) {
|
||||||
if (Filesystem::isFileBlacklisted($path)) {
|
if (Filesystem::isFileBlacklisted($path)) {
|
||||||
throw new ForbiddenException('Invalid path', false);
|
throw new ForbiddenException('Invalid path: ' . $path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fullPath = $this->datadir . $path;
|
$fullPath = $this->datadir . $path;
|
||||||
|
|
Loading…
Reference in New Issue