Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make the throttling O(2^n) instead of O(n^n)
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Aug 19, 2020
commit 6f751d01dbe84b7564c573e20e9264d53b19c48a
18 changes: 9 additions & 9 deletions lib/private/Security/Bruteforce/Throttler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
class Throttler {
public const LOGIN_ACTION = 'login';
public const MAX_DELAY = 25;
public const MAX_ATTEMPTS = 10;

/** @var IDBConnection */
private $db;
Expand Down Expand Up @@ -260,18 +261,17 @@ public function getDelay(string $ip, string $action = ''): int {
return 0;
}

$maxDelay = self::MAX_DELAY;
$firstDelay = 0.1;
if ($attempts > (8 * PHP_INT_SIZE - 1)) {
if ($attempts > self::MAX_ATTEMPTS) {
// Don't ever overflow. Just assume the maxDelay time:s
$firstDelay = $maxDelay;
} else {
$firstDelay *= pow(2, $attempts);
if ($firstDelay > $maxDelay) {
$firstDelay = $maxDelay;
}
return self::MAX_DELAY;
}

$delay = $firstDelay * 2**$attempts;
if ($delay > self::MAX_DELAY) {
return self::MAX_DELAY;
}
return (int) \ceil($firstDelay * 1000);
return (int) \ceil($delay * 1000);
}

/**
Expand Down