Browse Source

Merge pull request #44320 from nextcloud/backport/39990/stable28

[stable28] add some recrusive detection/prevention
tags/v28.0.4
Stephan Orbaugh 2 months ago
parent
commit
08444f45f1
No account linked to committer's email address

+ 14
- 0
apps/files_sharing/lib/SharedStorage.php View File

@@ -40,6 +40,7 @@ use OC\Files\Storage\Common;
use OC\Files\Storage\FailedStorage;
use OC\Files\Storage\Home;
use OC\Files\Storage\Wrapper\PermissionsMask;
use OC\Files\Storage\Wrapper\Wrapper;
use OC\User\DisplayNameCache;
use OC\User\NoUserException;
use OCA\Files_External\Config\ExternalMountPoint;
@@ -96,6 +97,8 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto

private string $sourcePath = '';

private static int $initDepth = 0;

public function __construct($arguments) {
$this->ownerView = $arguments['ownerView'];
$this->logger = \OC::$server->get(LoggerInterface::class);
@@ -135,8 +138,15 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
if ($this->initialized) {
return;
}

$this->initialized = true;
self::$initDepth++;

try {
if (self::$initDepth > 10) {
throw new \Exception("Maximum share depth reached");
}

/** @var IRootFolder $rootFolder */
$rootFolder = \OC::$server->get(IRootFolder::class);
$this->ownerUserFolder = $rootFolder->getUserFolder($this->superShare->getShareOwner());
@@ -149,6 +159,9 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
$this->cache = new FailedCache();
$this->rootPath = '';
} else {
if ($this->nonMaskedStorage instanceof Wrapper && $this->nonMaskedStorage->isWrapperOf($this)) {
throw new \Exception('recursive share detected');
}
$this->nonMaskedStorage = $ownerNode->getStorage();
$this->sourcePath = $ownerNode->getPath();
$this->rootPath = $ownerNode->getInternalPath();
@@ -177,6 +190,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
if (!$this->nonMaskedStorage) {
$this->nonMaskedStorage = $this->storage;
}
self::$initDepth--;
}

/**

+ 11
- 0
lib/private/Files/Storage/Wrapper/Wrapper.php View File

@@ -663,4 +663,15 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea
public function getDirectoryContent($directory): \Traversable {
return $this->getWrapperStorage()->getDirectoryContent($directory);
}

public function isWrapperOf(IStorage $storage) {
$wrapped = $this->getWrapperStorage();
if ($wrapped === $storage) {
return true;
}
if ($wrapped instanceof Wrapper) {
return $wrapped->isWrapperOf($storage);
}
return false;
}
}

Loading…
Cancel
Save