diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index 7b05c3e8fd45d..7de496e8fba1a 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -20,6 +20,7 @@ use OCP\Constants; use OCP\Files\FileInfo; use OCP\Files\IMimeTypeDetector; +use OCP\Files\NotPermittedException; use OCP\ICache; use OCP\ICacheFactory; use OCP\ITempManager; @@ -772,7 +773,15 @@ public function writeStream(string $path, $stream, ?int $size = null): int { } $path = $this->normalizePath($path); - $this->writeObject($path, $stream, $this->mimeDetector->detectPath($path)); + try { + $this->writeObject($path, $stream, $this->mimeDetector->detectPath($path)); + } catch (S3Exception $exception) { + $this->logger->error($exception->getMessage(), [ + 'app' => 'files_external', + 'exception' => $exception, + ]); + throw new NotPermittedException($exception->getMessage(), $exception->getCode(), $exception); + } $this->invalidateCache($path); return $size; diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 31ededf5f1be4..35e4a0425913f 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -32,6 +32,7 @@ use OCP\Files\IFilenameValidator; use OCP\Files\IMimeTypeDetector; use OCP\Files\InvalidPathException; +use OCP\Files\NotPermittedException; use OCP\Files\Storage\IConstructableStorage; use OCP\Files\Storage\ILockingStorage; use OCP\Files\Storage\IStorage; @@ -562,6 +563,9 @@ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalP try { $this->writeStream($targetInternalPath, $source); $result = true; + } catch (NotPermittedException $e) { + Server::get(LoggerInterface::class)->warning('Failed to copy stream to storage', ['exception' => $e]); + throw new ForbiddenException($e->getMessage(), false, $e); } catch (\Exception $e) { Server::get(LoggerInterface::class)->warning('Failed to copy stream to storage', ['exception' => $e]); }