Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable21] show better error messages when a file with a forbidden path is encountered #26291

Merged
merged 1 commit into from
Mar 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,14 @@ public function unlink($path) {
}
}

private function treeContainsBlacklistedFile(string $path): bool {
private function checkTreeForForbiddenItems(string $path) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
foreach ($iterator as $file) {
/** @var \SplFileInfo $file */
if (Filesystem::isFileBlacklisted($file->getBasename())) {
return true;
throw new ForbiddenException('Invalid path: ' . $file->getPathname(), false);
}
}

return false;
}

public function rename($path1, $path2) {
Expand Down Expand Up @@ -337,9 +335,7 @@ public function rename($path1, $path2) {
return $result;
}

if ($this->treeContainsBlacklistedFile($this->getSourcePath($path1))) {
throw new ForbiddenException('Invalid path', false);
}
$this->checkTreeForForbiddenItems($this->getSourcePath($path1));
}

return rename($this->getSourcePath($path1), $this->getSourcePath($path2));
Expand Down Expand Up @@ -437,7 +433,7 @@ public function hasUpdated($path, $time) {
*/
public function getSourcePath($path) {
if (Filesystem::isFileBlacklisted($path)) {
throw new ForbiddenException('Invalid path', false);
throw new ForbiddenException('Invalid path: ' . $path, false);
}

$fullPath = $this->datadir . $path;
Expand Down