Skip to content

Commit f0a229c

Browse files
Merge pull request #50880 from nextcloud/backport/50873/stable31
[stable31] fix(files_sharing): block downloading if needed
2 parents f7e9388 + 28fd638 commit f0a229c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

apps/files_sharing/lib/Controller/ShareController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,11 @@ public function downloadShare($token, $files = null, $path = '') {
359359
return new DataResponse('Share has no read permission');
360360
}
361361

362+
$attributes = $share->getAttributes();
363+
if ($attributes?->getAttribute('permissions', 'download') === false) {
364+
return new DataResponse('Share has no download permission');
365+
}
366+
362367
if (!$this->validateShare($share)) {
363368
throw new NotFoundException();
364369
}

apps/files_sharing/tests/Controller/ShareControllerTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use OCP\Security\ISecureRandom;
4343
use OCP\Server;
4444
use OCP\Share\Exceptions\ShareNotFound;
45+
use OCP\Share\IAttributes;
4546
use OCP\Share\IPublicShareTemplateFactory;
4647
use OCP\Share\IShare;
4748
use PHPUnit\Framework\MockObject\MockObject;
@@ -690,6 +691,34 @@ public function testDownloadShareWithCreateOnlyShare(): void {
690691
$this->assertEquals($expectedResponse, $response);
691692
}
692693

694+
public function testDownloadShareWithoutDownloadPermission(): void {
695+
$attributes = $this->createMock(IAttributes::class);
696+
$attributes->expects(self::once())
697+
->method('getAttribute')
698+
->with('permissions', 'download')
699+
->willReturn(false);
700+
701+
$share = $this->createMock(IShare::class);
702+
$share->method('getPassword')->willReturn('password');
703+
$share->expects(self::once())
704+
->method('getPermissions')
705+
->willReturn(Constants::PERMISSION_READ);
706+
$share->expects(self::once())
707+
->method('getAttributes')
708+
->willReturn($attributes);
709+
710+
$this->shareManager
711+
->expects(self::once())
712+
->method('getShareByToken')
713+
->with('validtoken')
714+
->willReturn($share);
715+
716+
// Test with a password protected share and no authentication
717+
$response = $this->shareController->downloadShare('validtoken');
718+
$expectedResponse = new DataResponse('Share has no download permission');
719+
$this->assertEquals($expectedResponse, $response);
720+
}
721+
693722
public function testDisabledOwner(): void {
694723
$this->shareController->setToken('token');
695724

0 commit comments

Comments
 (0)