Skip to content

Commit b19a568

Browse files
committed
SA-CORE-2025-008 by damienmckenna, tame4tex, benjifisher, mohit_aghera, larowlan, mingsong, xjm, neclimdul, catch, drumm, poker10
1 parent 201b506 commit b19a568

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

modules/system/src/FileDownloadController.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\system;
44

55
use Drupal\Core\Controller\ControllerBase;
6+
use Drupal\Core\Site\Settings;
67
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
78
use Symfony\Component\HttpFoundation\BinaryFileResponse;
89
use Symfony\Component\HttpFoundation\Request;
@@ -74,9 +75,24 @@ public function download(Request $request, $scheme = 'private') {
7475
if (count($headers)) {
7576
// \Drupal\Core\EventSubscriber\FinishResponseSubscriber::onRespond()
7677
// sets response as not cacheable if the Cache-Control header is not
77-
// already modified. We pass in FALSE for non-private schemes for the
78-
// $public parameter to make sure we don't change the headers.
79-
return new BinaryFileResponse($uri, 200, $headers, $scheme !== 'private');
78+
// already modified. Pass in FALSE for the $public parameter so that
79+
// existing headers from hook_file_download() are preserved. If any of
80+
// those headers set a Cache-Control header, return the response.
81+
$response = new BinaryFileResponse($uri, 200, $headers, FALSE);
82+
if ($response->headers->has('Cache-Control')) {
83+
return $response;
84+
}
85+
86+
// If there is no Cache-Control header, then respect the
87+
// file_additional_public_schemes setting, but never treat the core
88+
// 'private' or 'temporary' schemes as cacheable.
89+
$additional_public_schemes = array_diff(
90+
Settings::get('file_additional_public_schemes', []),
91+
['private', 'temporary'],
92+
);
93+
return in_array($scheme, $additional_public_schemes, TRUE)
94+
? $response->setPublic()
95+
: $response->setPrivate();
8096
}
8197

8298
throw new AccessDeniedHttpException();

0 commit comments

Comments
 (0)