Skip to content

Commit ed1a86a

Browse files
committed
fix: Prevent download of view-only files (one more case)
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent aa6c216 commit ed1a86a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

apps/files/lib/Controller/ConversionApiController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
use OCP\AppFramework\OCS\OCSForbiddenException;
2222
use OCP\AppFramework\OCS\OCSNotFoundException;
2323
use OCP\AppFramework\OCSController;
24+
use OCP\EventDispatcher\IEventDispatcher;
2425
use OCP\Files\Conversion\IConversionManager;
26+
use OCP\Files\Events\BeforeDirectFileDownloadEvent;
2527
use OCP\Files\File;
2628
use OCP\Files\GenericFileException;
2729
use OCP\Files\IRootFolder;
@@ -37,6 +39,7 @@ public function __construct(
3739
private IRootFolder $rootFolder,
3840
private IL10N $l10n,
3941
private ?string $userId,
42+
private IEventDispatcher $eventDispatcher,
4043
) {
4144
parent::__construct($appName, $request);
4245
}
@@ -67,6 +70,13 @@ public function convert(int $fileId, string $targetMimeType, ?string $destinatio
6770
throw new OCSNotFoundException($this->l10n->t('The file cannot be found'));
6871
}
6972

73+
$event = new BeforeDirectFileDownloadEvent($userFolder->getRelativePath($file->getPath()));
74+
$this->eventDispatcher->dispatchTyped($event);
75+
76+
if ($event->isSuccessful() === false) {
77+
throw new OCSForbiddenException('Permission denied to download file');
78+
}
79+
7080
if ($destination !== null) {
7181
$destination = PathHelper::normalizePath($destination);
7282
$parentDir = dirname($destination);

0 commit comments

Comments
 (0)