diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index f651ab4b462..125be5a27f5 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -115,7 +115,7 @@ jobs: npm_package_name: ${{ env.APP_NAME }} - name: Upload test failure screenshots - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: failure() with: name: Upload screenshots @@ -123,7 +123,7 @@ jobs: retention-days: 5 - name: Upload nextcloud logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: failure() with: name: Upload nextcloud log diff --git a/lib/Service/AttachmentService.php b/lib/Service/AttachmentService.php index d1157f3dd7e..ac5b7454a67 100644 --- a/lib/Service/AttachmentService.php +++ b/lib/Service/AttachmentService.php @@ -36,6 +36,7 @@ use OCP\Files\NotPermittedException; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IPreview; +use OCP\ISession; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IShare; use OCP\Util; @@ -56,6 +57,10 @@ class AttachmentService { * @var IPreview */ private $previewManager; + /** + * @var ISession + */ + private $session; /** * @var IMimeTypeDetector */ @@ -64,10 +69,12 @@ class AttachmentService { public function __construct(IRootFolder $rootFolder, ShareManager $shareManager, IPreview $previewManager, + ISession $session, IMimeTypeDetector $mimeTypeDetector) { $this->rootFolder = $rootFolder; $this->shareManager = $shareManager; $this->previewManager = $previewManager; + $this->session = $session; $this->mimeTypeDetector = $mimeTypeDetector; } @@ -529,6 +536,27 @@ private function getTextFilePublic(?int $documentId, string $shareToken): File { try { $share = $this->shareManager->getShareByToken($shareToken); if ($share->getShareType() === IShare::TYPE_LINK) { + + // check for password if required + /** @psalm-suppress RedundantConditionGivenDocblockType */ + if ($share->getPassword() !== null) { + $shareId = $this->session->get('public_link_authenticated'); + if ($share->getId() !== $shareId) { + throw new ShareNotFound(); + } + } + + // check read permission + if (($share->getPermissions() & Constants::PERMISSION_READ) !== Constants::PERMISSION_READ) { + throw new ShareNotFound(); + } + + // check download permission + $attributes = $share->getAttributes(); + if ($attributes !== null && $attributes->getAttribute('permissions', 'download') === false) { + throw new ShareNotFound(); + } + // shared file or folder? if ($share->getNodeType() === 'file') { $textFile = $share->getNode();