Skip to content

Commit

Permalink
Do not handle downloads for other elements on the same page (see #5573)
Browse files Browse the repository at this point in the history
Description
-----------

-

Commits
-------

ee0229a do not handle downloads for other elements on the same page
a50d049 simplify logic
  • Loading branch information
m-vo committed Dec 14, 2022
1 parent bb87ef7 commit 0941be9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions core-bundle/src/Controller/ContentElement/DownloadsController.php
Expand Up @@ -59,7 +59,7 @@ protected function getResponse(FragmentTemplate $template, ContentModel $model,
// TODO: Remove method and move logic into its own action, once we have
// a strategy how to handle permissions for downloads via a real route.
// See #4862 for more details.
$this->handleDownload($request);
$this->handleDownload($request, $model);

$filesystemItems = $this->getFilesystemItems($model);

Expand Down Expand Up @@ -222,16 +222,19 @@ private function getPreviews(FilesystemItem $filesystemItem, ContentModel $model
}
}

private function handleDownload(Request $request): void
private function handleDownload(Request $request, ContentModel $model): void
{
$response = $this->fileDownloadHelper->handle(
$request,
$this->filesStorage,
function (FilesystemItem $item, array $context): Response|null {
if (
null === ($model = $this->getContaoAdapter(ContentModel::class)->findById($context['id'] ?? null)) ||
!$this->getFilesystemItems($model)->any(static fn (FilesystemItem $listItem) => $listItem->getPath() === $item->getPath())
) {
function (FilesystemItem $item, array $context) use ($model): Response|null {
// Do not handle downloads from other DownloadController
// elements on the same page (see #5568)
if ($model->id !== ($context['id'] ?? null)) {
return new Response('', Response::HTTP_NO_CONTENT);
}

if (!$this->getFilesystemItems($model)->any(static fn (FilesystemItem $listItem) => $listItem->getPath() === $item->getPath())) {
return new Response('The resource can not be accessed anymore.', Response::HTTP_GONE);
}

Expand Down

0 comments on commit 0941be9

Please sign in to comment.