Skip to content

Commit 6e20eee

Browse files
authored
Merge pull request #5587 from nextcloud/fix/secure-view-template-creation-blocked
fix(secure-view): allow server-side file reads in SecureViewWrapper
2 parents dc40e52 + 1eff565 commit 6e20eee

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

lib/Storage/SecureViewWrapper.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCP\Files\ForbiddenException;
1616
use OCP\Files\IRootFolder;
1717
use OCP\Files\Storage\IStorage;
18+
use OCP\IRequest;
1819
use OCP\IUserSession;
1920
use OCP\Server;
2021

@@ -24,6 +25,7 @@ class SecureViewWrapper extends Wrapper {
2425
private IRootFolder $rootFolder;
2526
private IUserSession $userSession;
2627
private SecureViewService $secureViewService;
28+
private IRequest $request;
2729

2830
private string $mountPoint;
2931

@@ -35,6 +37,7 @@ public function __construct(array $parameters) {
3537
$this->rootFolder = Server::get(IRootFolder::class);
3638
$this->userSession = Server::get(IUserSession::class);
3739
$this->secureViewService = Server::get(SecureViewService::class);
40+
$this->request = Server::get(IRequest::class);
3841

3942
$this->mountPoint = $parameters['mountPoint'];
4043
}
@@ -85,7 +88,12 @@ public function rename(string $source, string $target): bool {
8588
* @throws ForbiddenException
8689
*/
8790
private function checkFileAccess(string $path): void {
88-
if (!$this->wopiMiddleware->isWOPIRequest() && $this->secureViewService->shouldSecure($path, $this, false)) {
91+
// Only block direct client-facing downloads (GET requests). Server-side operations
92+
// such as template creation and background jobs are non-GET or have no HTTP context
93+
// and must not be blocked even when secure view applies.
94+
if (!$this->wopiMiddleware->isWOPIRequest()
95+
&& $this->request->getMethod() === 'GET'
96+
&& $this->secureViewService->shouldSecure($path, $this, false)) {
8997
throw new ForbiddenException('Download blocked due the secure view policy', false);
9098
}
9199
}

0 commit comments

Comments
 (0)