aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Controller
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2025-01-25 19:46:19 +0100
committerFerdinand Thiessen <opensource@fthiessen.de>2025-01-26 15:21:09 +0100
commit08319ad5a6f9075e3afe9dd74ccfef147d447eea (patch)
tree7010b625275e4aa9eeafea36af2cb5fa15f804c6 /apps/files/lib/Controller
parent6b6401f9c8a82bd1ed66477043677e23a1e97dd3 (diff)
downloadnextcloud-server-08319ad5a6f9075e3afe9dd74ccfef147d447eea.tar.gz
nextcloud-server-08319ad5a6f9075e3afe9dd74ccfef147d447eea.zip
fix(files): Harden thumbnail endpoint
- Catch all thrown exceptions and handle in such a way you do not get information about forbidden files. - Resepect download permissions of shares. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/files/lib/Controller')
-rw-r--r--apps/files/lib/Controller/ApiController.php23
1 files changed, 17 insertions, 6 deletions
diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php
index dba732c9c52..9b9a0980389 100644
--- a/apps/files/lib/Controller/ApiController.php
+++ b/apps/files/lib/Controller/ApiController.php
@@ -29,8 +29,11 @@ use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\StreamResponse;
use OCP\Files\File;
use OCP\Files\Folder;
+use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
+use OCP\Files\Storage\ISharedStorage;
use OCP\Files\StorageNotAvailableException;
use OCP\IConfig;
use OCP\IL10N;
@@ -92,20 +95,28 @@ class ApiController extends Controller {
}
try {
- $file = $this->userFolder->get($file);
- if ($file instanceof Folder) {
+ $file = $this->userFolder?->get($file);
+ if ($file === null
+ || !($file instanceof File)
+ || ($file->getId() <= 0)
+ ) {
throw new NotFoundException();
}
- if ($file->getId() <= 0) {
- return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
+ // Validate the user is allowed to download the file (preview is some kind of download)
+ $storage = $file->getStorage();
+ if ($storage->instanceOfStorage(ISharedStorage::class)) {
+ /** @var ISharedStorage $storage */
+ $attributes = $storage->getShare()->getAttributes();
+ if ($attributes !== null && $attributes->getAttribute('permissions', 'download') === false) {
+ throw new NotFoundException();
+ }
}
- /** @var File $file */
$preview = $this->previewManager->getPreview($file, $x, $y, true);
return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
- } catch (NotFoundException $e) {
+ } catch (NotFoundException|NotPermittedException|InvalidPathException) {
return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
} catch (\Exception $e) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);