From 5215b8b6ef15838b124b6e8f2c6e19f209d0757d Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Thu, 7 Nov 2024 09:59:47 +0100 Subject: [PATCH] fix: Properly throttle in error cases and add rate limit for public file creation Signed-off-by: Julius Knorr --- lib/Controller/DocumentAPIController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Controller/DocumentAPIController.php b/lib/Controller/DocumentAPIController.php index d8dcdb1dc1..a34a67b0d0 100644 --- a/lib/Controller/DocumentAPIController.php +++ b/lib/Controller/DocumentAPIController.php @@ -78,6 +78,7 @@ public function __construct(IRequest $request, IRootFolder $rootFolder, IManager * @NoAdminRequired * @PublicPage * @BruteForceProtection(action=richdocumentsCreatePublic) + * @AnonRateThrottle(limit: 5, period: 120) */ public function create(string $mimeType, string $fileName, string $directoryPath = '/', string $shareToken = null, ?int $templateId = null): JSONResponse { try { @@ -105,10 +106,12 @@ public function create(string $mimeType, string $fileName, string $directoryPath } } catch (Throwable $e) { $this->logger->error('Failed to create document', ['exception' => $e]); - return new JSONResponse([ + $response = new JSONResponse([ 'status' => 'error', 'message' => $this->l10n->t('Cannot create document') ], Http::STATUS_BAD_REQUEST); + $response->throttle(); + return $response; } $basename = $this->l10n->t('New Document.odt');