Skip to content

Commit 75c0bf3

Browse files
authored
Merge pull request #5635 from nextcloud/fix/richdocuments-secureview-conversion-bypass
fix(richdocuments): gate conversion with SecureViewService check
2 parents e0b580d + dde412f commit 75c0bf3

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

lib/Conversion/ConversionProvider.php

Lines changed: 21 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,24 @@ 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+
false,
156+
);
157+
} catch (NotFoundException $e) {
158+
$this->logger->warning('Could not determine Secure View status for conversion target', ['exception' => $e]);
159+
throw new \Exception($this->l10n->t('Conversion is unavailable for this file.'));
160+
}
161+
if ($secured) {
162+
throw new \Exception($this->l10n->t(
163+
'Conversion is blocked because the file is protected by Secure View.'
164+
));
165+
}
166+
}
167+
147168
return $this->remoteService->convertFileTo($file, $targetFileExtension);
148169
}
149170

0 commit comments

Comments
 (0)