Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, 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.
*
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
Loading