diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-02-18 11:58:12 +0100 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2025-02-18 13:31:31 +0000 |
commit | 28fd6380173f1d8c26b33ac63b9cda50dd2154db (patch) | |
tree | 483946158aa1f6f9a618c6b83e175e1549b951a6 | |
parent | 1255a482ddf95e1256450e0ac16548a4d49a8f46 (diff) | |
download | nextcloud-server-backport/50873/stable31.tar.gz nextcloud-server-backport/50873/stable31.zip |
fix(files_sharing): block downloading if neededbackport/50873/stable31
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareController.php | 5 | ||||
-rw-r--r-- | apps/files_sharing/tests/Controller/ShareControllerTest.php | 29 |
2 files changed, 34 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index 1c3c9534dde..cfd9628410e 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -359,6 +359,11 @@ class ShareController extends AuthPublicShareController { return new DataResponse('Share has no read permission'); } + $attributes = $share->getAttributes(); + if ($attributes?->getAttribute('permissions', 'download') === false) { + return new DataResponse('Share has no download permission'); + } + if (!$this->validateShare($share)) { throw new NotFoundException(); } diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php index bc8e5dede63..9c9cd576517 100644 --- a/apps/files_sharing/tests/Controller/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php @@ -42,6 +42,7 @@ use OCP\IUserManager; use OCP\Security\ISecureRandom; use OCP\Server; use OCP\Share\Exceptions\ShareNotFound; +use OCP\Share\IAttributes; use OCP\Share\IPublicShareTemplateFactory; use OCP\Share\IShare; use PHPUnit\Framework\MockObject\MockObject; @@ -690,6 +691,34 @@ class ShareControllerTest extends \Test\TestCase { $this->assertEquals($expectedResponse, $response); } + public function testDownloadShareWithoutDownloadPermission(): void { + $attributes = $this->createMock(IAttributes::class); + $attributes->expects(self::once()) + ->method('getAttribute') + ->with('permissions', 'download') + ->willReturn(false); + + $share = $this->createMock(IShare::class); + $share->method('getPassword')->willReturn('password'); + $share->expects(self::once()) + ->method('getPermissions') + ->willReturn(Constants::PERMISSION_READ); + $share->expects(self::once()) + ->method('getAttributes') + ->willReturn($attributes); + + $this->shareManager + ->expects(self::once()) + ->method('getShareByToken') + ->with('validtoken') + ->willReturn($share); + + // Test with a password protected share and no authentication + $response = $this->shareController->downloadShare('validtoken'); + $expectedResponse = new DataResponse('Share has no download permission'); + $this->assertEquals($expectedResponse, $response); + } + public function testDisabledOwner(): void { $this->shareController->setToken('token'); |