-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Only mask the permissions for the users home directory for public shares #59511
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
lib/private/Files/Cache/Wrapper/CacheDirPermissionsMask.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OC\Files\Cache\Wrapper; | ||
|
|
||
| use Closure; | ||
| use OCP\Files\Cache\ICache; | ||
| use OCP\Files\Cache\ICacheEntry; | ||
|
|
||
| class CacheDirPermissionsMask extends CachePermissionsMask { | ||
| /** | ||
| * @param Closure(string $path): bool $checkPath | ||
| */ | ||
| public function __construct( | ||
| ICache $cache, | ||
| int $mask, | ||
| private readonly Closure $checkPath, | ||
| ) { | ||
| parent::__construct($cache, $mask); | ||
| } | ||
|
|
||
| protected function formatCacheEntry($entry): ICacheEntry|false { | ||
| $checkPath = $this->checkPath; | ||
| if ($checkPath($entry['path'])) { | ||
| return parent::formatCacheEntry($entry); | ||
| } | ||
|
|
||
| return $entry; | ||
| } | ||
| } |
193 changes: 193 additions & 0 deletions
193
lib/private/Files/Storage/Wrapper/DirPermissionsMask.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-only AND (AGPL-3.0-or-later OR AGPL-3.0-only) | ||
| */ | ||
|
|
||
| namespace OC\Files\Storage\Wrapper; | ||
|
|
||
| use OC\Files\Cache\Wrapper\CacheDirPermissionsMask; | ||
| use OC\Files\Storage\Storage; | ||
| use OCP\Files\Cache\ICache; | ||
|
|
||
| /** | ||
| * While PermissionMask can mask a whole storage this can | ||
| * mask a certain directory inside a storage | ||
| */ | ||
| class DirPermissionsMask extends PermissionsMask { | ||
|
|
||
| /** | ||
| * @var string the dir that should be masked | ||
| */ | ||
| private readonly string $path; | ||
|
|
||
| /** | ||
| * @var int remember length | ||
| */ | ||
| private readonly int $pathLength; | ||
|
|
||
| /** | ||
| * @param array{storage: Storage, mask: int, path: string, ...} $parameters | ||
| * @psalm-suppress MoreSpecificImplementedParamType | ||
| * | ||
| * $storage: The storage the permissions mask should be applied on | ||
| * $mask: The permission bits that should be kept, a combination of the \OCP\Constant::PERMISSION_ constants | ||
| * $path: The path relative to the storage root that should be masked | ||
| */ | ||
| public function __construct($parameters) { | ||
| parent::__construct($parameters); | ||
| $this->path = rtrim((string)$parameters['path'], '/'); | ||
| $this->pathLength = strlen((string)$parameters['path']); | ||
| } | ||
|
|
||
| protected function checkPath(string $path): bool { | ||
| return $path === $this->path || substr($path, 0, $this->pathLength + 1) === $this->path . '/'; | ||
| } | ||
|
|
||
| public function isUpdatable($path): bool { | ||
| if ($this->checkPath($path)) { | ||
| return parent::isUpdatable($path); | ||
| } | ||
|
|
||
| return $this->storage->isUpdatable($path); | ||
| } | ||
|
|
||
| public function isCreatable($path): bool { | ||
| if ($this->checkPath($path)) { | ||
| return parent::isCreatable($path); | ||
| } | ||
|
|
||
| return $this->storage->isCreatable($path); | ||
| } | ||
|
|
||
| public function isDeletable($path): bool { | ||
| if ($this->checkPath($path)) { | ||
| return parent::isDeletable($path); | ||
| } | ||
|
|
||
| return $this->storage->isDeletable($path); | ||
| } | ||
|
|
||
| public function isSharable($path): bool { | ||
| if ($this->checkPath($path)) { | ||
| return parent::isSharable($path); | ||
| } | ||
|
|
||
| return $this->storage->isSharable($path); | ||
| } | ||
|
|
||
| public function getPermissions($path): int { | ||
| if ($this->checkPath($path)) { | ||
| return parent::getPermissions($path); | ||
| } | ||
|
|
||
| return $this->storage->getPermissions($path); | ||
| } | ||
|
|
||
| public function rename($source, $target): bool { | ||
| if (!$this->isUpdatable($source)) { | ||
| return false; | ||
| } | ||
|
|
||
| if ($this->file_exists($target)) { | ||
| if ($this->isUpdatable($target)) { | ||
| return $this->storage->rename($source, $target); | ||
| } | ||
| } else { | ||
| $parent = dirname($target); | ||
| if ($parent === '.') { | ||
| $parent = ''; | ||
| } | ||
|
|
||
| if ($this->isCreatable($parent)) { | ||
| return $this->storage->rename($source, $target); | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public function copy($source, $target): bool { | ||
| if (!$this->isReadable($source)) { | ||
| return false; | ||
| } | ||
|
|
||
| if ($this->file_exists($target)) { | ||
| if ($this->isUpdatable($target)) { | ||
| return $this->storage->copy($source, $target); | ||
| } | ||
| } else { | ||
| $parent = dirname($target); | ||
| if ($parent === '.') { | ||
| $parent = ''; | ||
| } | ||
|
|
||
| if ($this->isCreatable($parent)) { | ||
| return $this->storage->copy($source, $target); | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public function touch($path, $mtime = null): bool { | ||
| if ($this->checkPath($path)) { | ||
| return parent::touch($path); | ||
| } | ||
|
|
||
| return $this->storage->touch($path); | ||
| } | ||
|
|
||
| public function mkdir($path): bool { | ||
| // Always allow creating the path of the dir mask. | ||
| if ($path !== $this->path && $this->checkPath($path)) { | ||
| return parent::mkdir($path); | ||
| } | ||
|
|
||
| return $this->storage->mkdir($path); | ||
| } | ||
|
|
||
| public function rmdir($path): bool { | ||
| if ($this->checkPath($path)) { | ||
| return parent::rmdir($path); | ||
| } | ||
|
|
||
| return $this->storage->rmdir($path); | ||
| } | ||
|
|
||
| public function unlink($path): bool { | ||
| if ($this->checkPath($path)) { | ||
| return parent::unlink($path); | ||
| } | ||
|
|
||
| return $this->storage->unlink($path); | ||
| } | ||
|
|
||
| public function file_put_contents($path, $data): int|float|false { | ||
| if ($this->checkPath($path)) { | ||
| return parent::file_put_contents($path, $data); | ||
| } | ||
|
|
||
| return $this->storage->file_put_contents($path, $data); | ||
| } | ||
|
|
||
| public function fopen($path, $mode) { | ||
| if ($this->checkPath($path)) { | ||
| return parent::fopen($path, $mode); | ||
| } | ||
|
|
||
| return $this->storage->fopen($path, $mode); | ||
| } | ||
|
|
||
| public function getCache($path = '', $storage = null): ICache { | ||
| if (!$storage) { | ||
| $storage = $this; | ||
| } | ||
|
|
||
| $sourceCache = $this->storage->getCache($path, $storage); | ||
| return new CacheDirPermissionsMask($sourceCache, $this->mask, $this->checkPath(...)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaks the guests app again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix in nextcloud/guests#1529