Skip to content
Prev Previous commit
Next Next commit
feat(security): Add a "testing mode" for bruteforce protection that d…
…oesn't sleep

Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Aug 23, 2023
commit 97548e789fd09685d79ad4bf28c59d7067ca55b4
13 changes: 13 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,19 @@
*/
'auth.bruteforce.protection.enabled' => true,

/**
* Whether the bruteforce protection shipped with Nextcloud should be set to testing mode.
*
* In testing mode bruteforce attempts are still recorded, but the requests do
* not sleep/wait for the specified time. They will still abort with
* "429 Too Many Requests" when the maximum delay is reached.
* Enabling this is discouraged for security reasons
* and should only be done for debugging and on CI when running tests.
*
* Defaults to ``false``
*/
'auth.bruteforce.protection.testing' => false,

/**
* Whether the rate limit protection shipped with Nextcloud should be enabled or not.
*
Expand Down
8 changes: 6 additions & 2 deletions lib/private/Security/Bruteforce/Throttler.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ public function resetDelayForIP(string $ip): void {
*/
public function sleepDelay(string $ip, string $action = ''): int {
$delay = $this->getDelay($ip, $action);
usleep($delay * 1000);
if (!$this->config->getSystemValueBool('auth.bruteforce.protection.testing')) {
usleep($delay * 1000);
}
return $delay;
}

Expand All @@ -304,7 +306,9 @@ public function sleepDelayOrThrowOnMax(string $ip, string $action = ''): int {
'delay' => $delay,
]);
}
usleep($delay * 1000);
if (!$this->config->getSystemValueBool('auth.bruteforce.protection.testing')) {
usleep($delay * 1000);
}
return $delay;
}
}