Skip to content

Commit

Permalink
Check share attributes on preview endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Oct 25, 2022
1 parent e3aac7d commit 413f84e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apps/files_sharing/lib/Controller/PublicPreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public function getPreview(
return new DataResponse([], Http::STATUS_FORBIDDEN);
}

$attributes = $share->getAttributes();
if ($attributes !== null && $attributes->getAttribute('permissions', 'download') === false) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}

try {
$node = $share->getNode();
if ($node instanceof Folder) {
Expand Down Expand Up @@ -159,6 +164,11 @@ public function directLink(string $token) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}

$attributes = $share->getAttributes();
if ($attributes !== null && $attributes->getAttribute('permissions', 'download') === false) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}

try {
$node = $share->getNode();
if ($node instanceof Folder) {
Expand Down
12 changes: 12 additions & 0 deletions core/Controller/PreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
namespace OC\Core\Controller;

use OCA\Files_Sharing\SharedStorage;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
Expand All @@ -37,6 +38,7 @@
use OCP\Files\NotFoundException;
use OCP\IPreview;
use OCP\IRequest;
use OCP\Share\IShare;

class PreviewController extends Controller {
private string $userId;
Expand Down Expand Up @@ -129,6 +131,16 @@ private function fetchPreview(
return new DataResponse([], Http::STATUS_FORBIDDEN);
}

$storage = $node->getStorage();
if ($storage->instanceOfStorage(SharedStorage::class)) {
/** @var SharedStorage $storage */
$share = $storage->getShare();
$attributes = $share->getAttributes();
if ($attributes !== null && $attributes->getAttribute('permissions', 'download') === false) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
}

try {
$f = $this->preview->getPreview($node, $x, $y, !$a, $mode);
$response = new FileDisplayResponse($f, Http::STATUS_OK, [
Expand Down

0 comments on commit 413f84e

Please sign in to comment.