Skip to content

Commit fbb7727

Browse files
authored
Merge pull request #50905 from nextcloud/fix/rate-limit-share-creation
2 parents b2a187d + 50dcbde commit fbb7727

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ public function deleteShare(string $id): DataResponse {
558558
* 200: Share created
559559
*/
560560
#[NoAdminRequired]
561+
#[UserRateLimit(limit: 20, period: 600)]
561562
public function createShare(
562563
?string $path = null,
563564
?int $permissions = null,
@@ -2150,7 +2151,7 @@ private function checkInheritedAttributes(IShare $share): void {
21502151
* 200: The email notification was sent successfully
21512152
*/
21522153
#[NoAdminRequired]
2153-
#[UserRateLimit(limit: 5, period: 120)]
2154+
#[UserRateLimit(limit: 10, period: 600)]
21542155
public function sendShareEmail(string $id, $password = ''): DataResponse {
21552156
try {
21562157
$share = $this->getShareById($id);

build/integration/config/behat.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,14 @@ default:
243243
regular_user_password: 123456
244244
- RemoteContext:
245245
remote: http://localhost:8080
246+
247+
ratelimiting:
248+
paths:
249+
- "%paths.base%/../ratelimiting_features"
250+
contexts:
251+
- RateLimitingContext:
252+
baseUrl: http://localhost:8080
253+
admin:
254+
- admin
255+
- admin
256+
regular_user_password: 123456
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
4+
* SPDX-License-Identifier: AGPL-3.0-or-later
5+
*/
6+
use Behat\Behat\Context\Context;
7+
8+
class RateLimitingContext implements Context {
9+
use BasicStructure;
10+
use CommandLine;
11+
use Provisioning;
12+
13+
/**
14+
* @BeforeScenario @RateLimiting
15+
*/
16+
public function enableRateLimiting() {
17+
// Enable rate limiting for the tests.
18+
// Ratelimiting is disabled by default, so we need to enable it
19+
$this->runOcc(['config:system:set', 'ratelimit.protection.enabled', '--value', 'true', '--type', 'bool']);
20+
}
21+
22+
/**
23+
* @AfterScenario @RateLimiting
24+
*/
25+
public function disableRateLimiting() {
26+
// Restore the default rate limiting configuration.
27+
// Ratelimiting is disabled by default, so we need to disable it
28+
$this->runOcc(['config:system:set', 'ratelimit.protection.enabled', '--value', 'false', '--type', 'bool']);
29+
}
30+
}

build/integration/features/ratelimiting.feature renamed to build/integration/ratelimiting_features/ratelimiting.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
22
# SPDX-License-Identifier: AGPL-3.0-or-later
3+
@RateLimiting
34
Feature: ratelimiting
45

56
Background:

build/integration/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ INSTALLED=$($OCC status | grep installed: | cut -d " " -f 5)
2020
if [ "$INSTALLED" == "true" ]; then
2121
# Disable bruteforce protection because the integration tests do trigger them
2222
$OCC config:system:set auth.bruteforce.protection.enabled --value false --type bool
23+
# Disable rate limit protection because the integration tests do trigger them
24+
$OCC config:system:set ratelimit.protection.enabled --value false --type bool
2325
# Allow local remote urls otherwise we can not share
2426
$OCC config:system:set allow_local_remote_servers --value true --type bool
2527
# Allow self signed certificates

0 commit comments

Comments
 (0)