Skip to content

Commit

Permalink
reuse isValidPath from Filesystem
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Sep 4, 2023
1 parent baf8d2e commit 5ac0e9b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
10 changes: 2 additions & 8 deletions lib/private/Files/Node/LazyFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace OC\Files\Node;

use OC\Files\Filesystem;
use OC\Files\Utils\PathHelper;
use OCP\Files\Folder;
use OCP\Constants;
Expand Down Expand Up @@ -418,21 +419,14 @@ public function getExtension(): string {
public function getFullPath($path) {
if (isset($this->data['path'])) {
$path = PathHelper::normalizePath($path);
if (!$this->isValidPath($path)) {
if (!Filesystem::isValidPath($path)) {
throw new NotPermittedException('Invalid path "' . $path . '"');
}
return $this->data['path'] . $path;
}
return $this->__call(__FUNCTION__, func_get_args());
}

public function isValidPath($path) {
if (!str_starts_with($path, '/')) {
$path = '/' . $path;
}
return !(str_contains($path, '/../') || strrchr($path, '/') === '/..');
}

/**
* @inheritDoc
*/
Expand Down
8 changes: 1 addition & 7 deletions lib/private/Files/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,7 @@ protected function normalizePath($path) {
* @return bool
*/
public function isValidPath($path) {
if (!$path || $path[0] !== '/') {
$path = '/' . $path;
}
if (strstr($path, '/../') || strrchr($path, '/') === '/..') {
return false;
}
return true;
return Filesystem::isValidPath($path);
}

public function isMounted() {
Expand Down

0 comments on commit 5ac0e9b

Please sign in to comment.