Skip to content

Commit 53d5652

Browse files
Merge pull request #454 from nextcloud/backport/451/stable31
[stable31] feat: add user rate limiting for requests
2 parents cb5a0d8 + c39db41 commit 53d5652

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

js/app.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@
4747
$context.removeClass('loading');
4848
},
4949
error: function (response) {
50-
$context.prop('disabled', '');
51-
$context.removeClass('loading');
52-
if(response.responseJSON && response.responseJSON.ocs.data.error) {
53-
$context.siblings('span.warning')
54-
.removeClass('hidden')
55-
.html(response.responseJSON.ocs.data.error);
50+
if (response.status !== 429) {
51+
$context.prop('disabled', '');
5652
}
53+
54+
$context.removeClass('loading');
55+
56+
const errorMessage = response.status === 429
57+
? t('data_request', 'Already requested, please try again later.')
58+
: (response.responseJSON?.ocs?.data?.error || t('data_request', 'Request failed'));
59+
60+
$context.siblings('span.warning')
61+
.removeClass('hidden')
62+
.html(errorMessage);
5763
}
5864
});
5965
}

lib/Controller/DataRequestController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OCA\DataRequest\Exceptions\HintedRuntime;
1111
use OCA\DataRequest\Services\Request;
1212
use OCP\AppFramework\Http;
13+
use OCP\AppFramework\Http\Attribute\UserRateLimit;
1314
use OCP\AppFramework\Http\DataResponse;
1415
use OCP\AppFramework\OCSController;
1516
use OCP\IRequest;
@@ -33,6 +34,7 @@ public function __construct(
3334
* @NoAdminRequired
3435
* @PasswordConfirmationRequired
3536
*/
37+
#[UserRateLimit(limit: 1, period: 3600)]
3638
public function export(): DataResponse {
3739
return $this->processRequest(function (): void {
3840
$this->dataRequest->sendExportRequest();
@@ -43,6 +45,7 @@ public function export(): DataResponse {
4345
* @NoAdminRequired
4446
* @PasswordConfirmationRequired
4547
*/
48+
#[UserRateLimit(limit: 1, period: 3600)]
4649
public function deletion(): DataResponse {
4750
return $this->processRequest(function (): void {
4851
$this->dataRequest->sendDeleteRequest();

0 commit comments

Comments
 (0)