mirror of
https://github.com/nextcloud/server.git
synced 2026-02-19 02:38:40 -05:00
fix: add some recrusive detection/prevention
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
47ebc1119a
commit
ea8a774a0a
2 changed files with 26 additions and 1 deletions
|
|
@ -41,6 +41,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\NoUserException;
|
||||
use OCA\Files_External\Config\ConfigAdapter;
|
||||
use OCP\Constants;
|
||||
|
|
@ -97,6 +98,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);
|
||||
|
|
@ -136,8 +139,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());
|
||||
|
|
@ -148,6 +158,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();
|
||||
|
|
@ -176,6 +189,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
|
|||
if (!$this->nonMaskedStorage) {
|
||||
$this->nonMaskedStorage = $this->storage;
|
||||
}
|
||||
self::$initDepth--;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -409,7 +423,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
|
|||
return new FailedCache();
|
||||
}
|
||||
|
||||
$this->cache = new Cache(
|
||||
$this->cache = new \OCA\Files_Sharing\Cache(
|
||||
$storage,
|
||||
$sourceRoot,
|
||||
\OC::$server->get(CacheDependencies::class),
|
||||
|
|
|
|||
|
|
@ -654,4 +654,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…
Reference in a new issue