summaryrefslogtreecommitdiffstats
path: root/lib/private/Security
diff options
context:
space:
mode:
authorJohannes Riedel <joeried@users.noreply.github.com>2020-03-17 17:06:52 +0100
committerJohannes Riedel <joeried@users.noreply.github.com>2020-03-19 16:20:22 +0100
commit0c38569c83466b52013b7890432bcb6ae74df883 (patch)
treeb1471dd69a7ba4aa3a3e6b338debda8bb53d45e4 /lib/private/Security
parent25ce3c434b66195bfb0b347de6125d0fa1538898 (diff)
downloadnextcloud-server-0c38569c83466b52013b7890432bcb6ae74df883.tar.gz
nextcloud-server-0c38569c83466b52013b7890432bcb6ae74df883.zip
Implement occ command security:bruteforceattemps:reset-for-ip
Signed-off-by: Johannes Riedel <joeried@users.noreply.github.com>
Diffstat (limited to 'lib/private/Security')
-rw-r--r--lib/private/Security/Bruteforce/Throttler.php35
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/private/Security/Bruteforce/Throttler.php b/lib/private/Security/Bruteforce/Throttler.php
index b5a4dfbfaff..e53c3c66d37 100644
--- a/lib/private/Security/Bruteforce/Throttler.php
+++ b/lib/private/Security/Bruteforce/Throttler.php
@@ -89,6 +89,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