Skip to content

Commit

Permalink
chore(bruteforce): allows to configure max attempts before request abort
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Gaussorgues <[email protected]>
  • Loading branch information
Altahrim committed Dec 2, 2024
1 parent ce7b5eb commit 587f8a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,17 @@
*/
'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, changfe 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.
*
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Security/Bruteforce/Throttler.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function getDelay(string $ip, string $action = ''): int {
}

$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;
}
Expand Down Expand Up @@ -263,7 +263,7 @@ public function sleepDelay(string $ip, string $action = ''): int {
*/
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,
Expand Down

0 comments on commit 587f8a9

Please sign in to comment.