feat(security): Add a "testing mode" for bruteforce protection that doesn't sleep

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/39870/head
Joas Schilling 10 months ago
parent a95800c647
commit abc98d343c
No known key found for this signature in database
GPG Key ID: 74434EFE0D2E2205

@ -352,6 +352,19 @@ $CONFIG = [
*/ */
'auth.bruteforce.protection.enabled' => true, '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. * Whether the rate limit protection shipped with Nextcloud should be enabled or not.
* *

@ -280,7 +280,9 @@ class Throttler implements IThrottler {
*/ */
public function sleepDelay(string $ip, string $action = ''): int { public function sleepDelay(string $ip, string $action = ''): int {
$delay = $this->getDelay($ip, $action); $delay = $this->getDelay($ip, $action);
usleep($delay * 1000); if (!$this->config->getSystemValueBool('auth.bruteforce.protection.testing')) {
usleep($delay * 1000);
}
return $delay; return $delay;
} }
@ -304,7 +306,9 @@ class Throttler implements IThrottler {
'delay' => $delay, 'delay' => $delay,
]); ]);
} }
usleep($delay * 1000); if (!$this->config->getSystemValueBool('auth.bruteforce.protection.testing')) {
usleep($delay * 1000);
}
return $delay; return $delay;
} }
} }

Loading…
Cancel
Save