Skip to content

Commit 60cb2b6

Browse files
committed
fix(richdocuments): gate conversion with SecureViewService check
Server-side conversion bypassed the Secure View / watermark restriction that the viewer enforces, allowing a user with view-only secure access to download a clean copy via the conversion API. Reuse SecureViewService (same logic the viewer uses) to deny conversion for files that should be secured. Handle the documented NotFoundException so a cache miss surfaces as a clear, translated error instead of a 500. Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
1 parent d79b884 commit 60cb2b6

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

lib/Conversion/ConversionProvider.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
namespace OCA\Richdocuments\Conversion;
1111

1212
use OCA\Richdocuments\Service\RemoteService;
13+
use OCA\Richdocuments\Service\SecureViewService;
1314
use OCP\Files\Conversion\ConversionMimeProvider;
1415
use OCP\Files\Conversion\IConversionProvider;
1516
use OCP\Files\File;
17+
use OCP\Files\NotFoundException;
1618
use OCP\IL10N;
1719
use OCP\L10N\IFactory;
1820
use Psr\Log\LoggerInterface;
@@ -53,6 +55,7 @@ public function __construct(
5355
private RemoteService $remoteService,
5456
private LoggerInterface $logger,
5557
IFactory $l10nFactory,
58+
private SecureViewService $secureViewService,
5659
) {
5760
$this->l10n = $l10nFactory->get('richdocuments');
5861
}
@@ -144,6 +147,23 @@ public function convertFile(File $file, string $targetMimeType): mixed {
144147
));
145148
}
146149

150+
if ($this->secureViewService->isEnabled()) {
151+
try {
152+
$secured = $this->secureViewService->shouldSecure(
153+
$file->getInternalPath(),
154+
$file->getStorage(),
155+
);
156+
} catch (NotFoundException $e) {
157+
$this->logger->warning('Could not determine Secure View status for conversion target', ['exception' => $e]);
158+
throw new \Exception($this->l10n->t('Conversion is unavailable for this file.'));
159+
}
160+
if ($secured) {
161+
throw new \Exception($this->l10n->t(
162+
'Conversion is blocked because the file is protected by Secure View.'
163+
));
164+
}
165+
}
166+
147167
return $this->remoteService->convertFileTo($file, $targetFileExtension);
148168
}
149169

0 commit comments

Comments
 (0)