diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-11-23 13:37:50 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2017-11-24 14:58:57 +0100 |
commit | 5a270c271567d3c6ef9d0f1f78814b5b249ca2fe (patch) | |
tree | 8fca6e04dd9f978038b37f5cab94f06772f6ea84 /lib/private | |
parent | 2f3484ba88a05cdc85ccd5d66f11478999cf2903 (diff) | |
download | nextcloud-server-5a270c271567d3c6ef9d0f1f78814b5b249ca2fe.tar.gz nextcloud-server-5a270c271567d3c6ef9d0f1f78814b5b249ca2fe.zip |
Reset bruteforce attempt table on successful login
* only clear the entries that come from the same subnet, same action and same metadata
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Security/Bruteforce/Throttler.php | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/private/Security/Bruteforce/Throttler.php b/lib/private/Security/Bruteforce/Throttler.php index 1626cee8cb3..f08b721d143 100644 --- a/lib/private/Security/Bruteforce/Throttler.php +++ b/lib/private/Security/Bruteforce/Throttler.php @@ -243,6 +243,33 @@ class Throttler { } /** + * Reset the throttling delay for an IP address, action and metadata + * + * @param string $ip + * @param string $action + * @param string $metadata + */ + public function resetDelay($ip, $action, $metadata) { + $ipAddress = new IpAddress($ip); + if ($this->isIPWhitelisted((string)$ipAddress)) { + return; + } + + $cutoffTime = (new \DateTime()) + ->sub($this->getCutoff(43200)) + ->getTimestamp(); + + $qb = $this->db->getQueryBuilder(); + $qb->delete('bruteforce_attempts') + ->where($qb->expr()->gt('occurred', $qb->createNamedParameter($cutoffTime))) + ->andWhere($qb->expr()->eq('subnet', $qb->createNamedParameter($ipAddress->getSubnet()))) + ->andWhere($qb->expr()->eq('action', $qb->createNamedParameter($action))) + ->andWhere($qb->expr()->eq('metadata', $qb->createNamedParameter(json_encode($metadata)))); + + $qb->execute(); + } + + /** * Will sleep for the defined amount of time * * @param string $ip |