permissionManager = Server::get(PermissionManager::class); $this->wopiMiddleware = Server::get(WOPIMiddleware::class); $this->rootFolder = Server::get(IRootFolder::class); $this->userSession = Server::get(IUserSession::class); $this->secureViewService = Server::get(SecureViewService::class); $this->mountPoint = $parameters['mountPoint']; } public function fopen($path, $mode) { $this->checkFileAccess($path); return $this->storage->fopen($path, $mode); } public function file_get_contents(string $path): false|string { $this->checkFileAccess($path); return $this->storage->file_get_contents($path); } public function copy(string $source, string $target): bool { $this->checkSourceAndTarget($source, $target); return parent::copy($source, $target); } public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { $this->checkSourceAndTarget($sourceInternalPath, $targetInternalPath, $sourceStorage); return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { $this->checkSourceAndTarget($sourceInternalPath, $targetInternalPath, $sourceStorage); return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } public function rename(string $source, string $target): bool { $this->checkSourceAndTarget($source, $target); return parent::rename($source, $target); } /** * @throws ForbiddenException */ private function checkFileAccess(string $path): void { if (!$this->wopiMiddleware->isWOPIRequest() && $this->secureViewService->shouldSecure($path, $this, false)) { throw new ForbiddenException('Download blocked due the secure view policy', false); } } private function checkSourceAndTarget(string $source, string $target, ?IStorage $sourceStorage = null): void { if ($this->secureViewService->shouldSecure($source, $sourceStorage ?? $this, $sourceStorage !== null) && !$this->secureViewService->shouldSecure($target, $this) ) { throw new ForbiddenException('Download blocked due the secure view policy. The source requires secure view that the target cannot offer.', false); } } }