diff options
author | Stephan Orbaugh <62374139+sorbaugh@users.noreply.github.com> | 2024-03-25 15:27:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-25 15:27:27 +0100 |
commit | 08444f45f12bb3906ffa9cd45b721f258a7a6f4b (patch) | |
tree | e638213d76e4859e03fbe6b44b39ee8d58a79962 /apps | |
parent | d1a7e8860506dfcb0b08cc37e1a75081493324e3 (diff) | |
parent | 7d98e83e3f13d64eab893e27c943dcba9b54b808 (diff) | |
download | nextcloud-server-08444f45f12bb3906ffa9cd45b721f258a7a6f4b.tar.gz nextcloud-server-08444f45f12bb3906ffa9cd45b721f258a7a6f4b.zip |
Merge pull request #44320 from nextcloud/backport/39990/stable28
[stable28] add some recrusive detection/prevention
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/lib/SharedStorage.php | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index eb3074a102f..f41891c67f3 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -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--; } /** |