diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2017-01-17 11:51:10 +0100 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2017-01-18 15:25:15 +0100 |
commit | df296249d6ca4c9980bb23acdb6d9353d0d69996 (patch) | |
tree | 86f019d215dd92604164dd5da44ce1e9d7b4e41b /lib/private/Security | |
parent | 4bbd52b3f9aa07ebb170ed2ea4dbc67e2af79448 (diff) | |
download | nextcloud-server-df296249d6ca4c9980bb23acdb6d9353d0d69996.tar.gz nextcloud-server-df296249d6ca4c9980bb23acdb6d9353d0d69996.zip |
introduce brute force protection for api calls
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'lib/private/Security')
-rw-r--r-- | lib/private/Security/Bruteforce/Throttler.php | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/private/Security/Bruteforce/Throttler.php b/lib/private/Security/Bruteforce/Throttler.php index 031c5ffd411..765f109fdb3 100644 --- a/lib/private/Security/Bruteforce/Throttler.php +++ b/lib/private/Security/Bruteforce/Throttler.php @@ -189,9 +189,10 @@ class Throttler { * Get the throttling delay (in milliseconds) * * @param string $ip + * @param string $action optionally filter by action * @return int */ - public function getDelay($ip) { + public function getDelay($ip, $action = '') { $cutoffTime = (new \DateTime()) ->sub($this->getCutoff(43200)) ->getTimestamp(); @@ -201,6 +202,11 @@ class Throttler { ->from('bruteforce_attempts') ->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime))) ->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($this->getSubnet($ip)))); + + if ($action !== '') { + $qb->andWhere($qb->expr()->eq('action', $qb->createNamedParameter($action))); + } + $attempts = count($qb->execute()->fetchAll()); if ($attempts === 0) { @@ -225,10 +231,11 @@ class Throttler { * Will sleep for the defined amount of time * * @param string $ip + * @param string $action optionally filter by action * @return int the time spent sleeping */ - public function sleepDelay($ip) { - $delay = $this->getDelay($ip); + public function sleepDelay($ip, $action = '') { + $delay = $this->getDelay($ip, $action); usleep($delay * 1000); return $delay; } |