Skip to content

Commit

Permalink
Merge pull request #4202 from nextcloud/backport/4200/stable29
Browse files Browse the repository at this point in the history
[stable29] fix: Properly throttle in error cases and add rate limit for public file creation
  • Loading branch information
juliusknorr authored Nov 7, 2024
2 parents f1cbca9 + 9672112 commit fdad23a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Controller/DocumentAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCA\Richdocuments\Helper;
use OCA\Richdocuments\TemplateManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\AnonRateLimit;
use OCP\AppFramework\Http\Attribute\BruteForceProtection;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\PublicPage;
Expand Down Expand Up @@ -74,6 +75,7 @@ public function __construct(
#[NoAdminRequired]
#[PublicPage]
#[BruteForceProtection(action: 'richdocumentsCreatePublic')]
#[AnonRateLimit(limit: 5, period: 120)]
public function create(string $mimeType, string $fileName, string $directoryPath = '/', ?string $shareToken = null, ?int $templateId = null): JSONResponse {
try {
if ($shareToken !== null) {
Expand All @@ -100,10 +102,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');
Expand Down

0 comments on commit fdad23a

Please sign in to comment.