chore(bruteforce): allows to configure max attempts before request abort

Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
pull/49599/head
Benjamin Gaussorgues 5 months ago
parent e87ed9b5fb
commit 1fd19685f1
No known key found for this signature in database
GPG Key ID: 5DAC1CAFAA6DB883
  1. 11
      config/config.sample.php
  2. 4
      lib/private/Security/Bruteforce/Throttler.php

@ -431,6 +431,17 @@ $CONFIG = [
*/
'auth.bruteforce.protection.testing' => false,
/**
* Brute force protection: maximum number of attempts before blocking
*
* When more than max-attempts login requests are sent to Nextcloud, requests
* will abort with "429 Too Many Requests".
* For security reasons, change it only if you know what you are doing.
*
* Defaults to ``10``
*/
'auth.bruteforce.max-attempts' => 10,
/**
* Whether the rate limit protection shipped with Nextcloud should be enabled or not.
*

@ -195,7 +195,7 @@ class Throttler implements IThrottler {
}
$firstDelay = 0.1;
if ($attempts > self::MAX_ATTEMPTS) {
if ($attempts > $this->config->getSystemValueInt('auth.bruteforce.max-attempts', self::MAX_ATTEMPTS)) {
// Don't ever overflow. Just assume the maxDelay time:s
return self::MAX_DELAY_MS;
}
@ -263,7 +263,7 @@ class Throttler implements IThrottler {
*/
public function sleepDelayOrThrowOnMax(string $ip, string $action = ''): int {
$delay = $this->getDelay($ip, $action);
if (($delay === self::MAX_DELAY_MS) && $this->getAttempts($ip, $action, 0.5) > self::MAX_ATTEMPTS) {
if (($delay === self::MAX_DELAY_MS) && $this->getAttempts($ip, $action, 0.5) > $this->config->getSystemValueInt('auth.bruteforce.max-attempts', self::MAX_ATTEMPTS)) {
$this->logger->info('IP address blocked because it reached the maximum failed attempts in the last 30 minutes [action: {action}, ip: {ip}]', [
'action' => $action,
'ip' => $ip,

Loading…
Cancel
Save