diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-05-25 14:04:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-25 14:04:18 +0200 |
commit | e57bca31adc9a2591357825fa7042596fcb51f7d (patch) | |
tree | e7880a8fa58482fcfb07c104a5bf85de96b9cb8a /lib/private/Security/Bruteforce/Throttler.php | |
parent | cbde1d102c06f44d9b4f84cb3d72f9fbf0a3beb5 (diff) | |
parent | bd997a105cc582180bb36dad3ca8ffce25fc9e34 (diff) | |
download | nextcloud-server-e57bca31adc9a2591357825fa7042596fcb51f7d.tar.gz nextcloud-server-e57bca31adc9a2591357825fa7042596fcb51f7d.zip |
Merge pull request #20005 from joeried/occ-remove-bruteforce-attempts-by-ip
Implement occ command to reset bruteforce attemps from a given IP address
Diffstat (limited to 'lib/private/Security/Bruteforce/Throttler.php')
-rw-r--r-- | lib/private/Security/Bruteforce/Throttler.php | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/private/Security/Bruteforce/Throttler.php b/lib/private/Security/Bruteforce/Throttler.php index 1bece6a05d5..63c6361b9ce 100644 --- a/lib/private/Security/Bruteforce/Throttler.php +++ b/lib/private/Security/Bruteforce/Throttler.php @@ -90,6 +90,17 @@ class Throttler { } /** + * Calculate the cut off timestamp + * + * @return int + */ + private function getCutoffTimestamp(): int { + return (new \DateTime()) + ->sub($this->getCutoff(43200)) + ->getTimestamp(); + } + + /** * Register a failed attempt to bruteforce a security control * * @param string $action @@ -212,9 +223,7 @@ class Throttler { return 0; } - $cutoffTime = (new \DateTime()) - ->sub($this->getCutoff(43200)) - ->getTimestamp(); + $cutoffTime = $this->getCutoffTimestamp(); $qb = $this->db->getQueryBuilder(); $qb->select('*') @@ -259,9 +268,7 @@ class Throttler { return; } - $cutoffTime = (new \DateTime()) - ->sub($this->getCutoff(43200)) - ->getTimestamp(); + $cutoffTime = $this->getCutoffTimestamp(); $qb = $this->db->getQueryBuilder(); $qb->delete('bruteforce_attempts') @@ -274,6 +281,22 @@ class Throttler { } /** + * Reset the throttling delay for an IP address + * + * @param string $ip + */ + public function resetDelayForIP($ip) { + $cutoffTime = $this->getCutoffTimestamp(); + + $qb = $this->db->getQueryBuilder(); + $qb->delete('bruteforce_attempts') + ->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime))) + ->andWhere($qb->expr()->eq('ip', $qb->createNamedParameter($ip))); + + $qb->execute(); + } + + /** * Will sleep for the defined amount of time * * @param string $ip |