aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-08-15 08:04:32 +0200
committerJoas Schilling <coding@schilljs.com>2023-08-21 16:36:04 +0200
commitfd9b2d488e6083d6c1027551bb0190e5b7ee7a36 (patch)
tree4781506486a1950b19c28b2c8ff036e836e2bf03 /lib
parent2f06f2355d1f8a2963590c811c534a71dd7f0c7c (diff)
downloadnextcloud-server-fd9b2d488e6083d6c1027551bb0190e5b7ee7a36.tar.gz
nextcloud-server-fd9b2d488e6083d6c1027551bb0190e5b7ee7a36.zip
feat: Expose if the own IP is allowed to bypass bruteforce protection
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Security/Bruteforce/Capabilities.php32
-rw-r--r--lib/private/Security/Bruteforce/Throttler.php2
2 files changed, 12 insertions, 22 deletions
diff --git a/lib/private/Security/Bruteforce/Capabilities.php b/lib/private/Security/Bruteforce/Capabilities.php
index 60cf3086f2d..4eada3d05f5 100644
--- a/lib/private/Security/Bruteforce/Capabilities.php
+++ b/lib/private/Security/Bruteforce/Capabilities.php
@@ -3,9 +3,11 @@
declare(strict_types=1);
/**
+ * @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
* @copyright Copyright (c) 2017 Roeland Jago Douma <roeland@famdouma.nl>
*
* @author J0WI <J0WI@users.noreply.github.com>
+ * @author Joas Schilling <coding@schilljs.com>
* @author Julius Härtl <jus@bitgrid.net>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
@@ -32,33 +34,21 @@ use OCP\Capabilities\IInitialStateExcludedCapability;
use OCP\IRequest;
class Capabilities implements IPublicCapability, IInitialStateExcludedCapability {
- /** @var IRequest */
- private $request;
-
- /** @var Throttler */
- private $throttler;
+ public function __construct(
+ private IRequest $request,
+ private Throttler $throttler,
+ ) {
+ }
/**
- * Capabilities constructor.
- *
- * @param IRequest $request
- * @param Throttler $throttler
+ * @return array{bruteforce: array{delay: int, allow-listed: bool}}
*/
- public function __construct(IRequest $request,
- Throttler $throttler) {
- $this->request = $request;
- $this->throttler = $throttler;
- }
-
public function getCapabilities(): array {
- if (version_compare(\OC::$server->getConfig()->getSystemValueString('version', '0.0.0.0'), '12.0.0.0', '<')) {
- return [];
- }
-
return [
'bruteforce' => [
- 'delay' => $this->throttler->getDelay($this->request->getRemoteAddress())
- ]
+ 'delay' => $this->throttler->getDelay($this->request->getRemoteAddress()),
+ 'allow-listed' => $this->throttler->isIPWhitelisted($this->request->getRemoteAddress()),
+ ],
];
}
}
diff --git a/lib/private/Security/Bruteforce/Throttler.php b/lib/private/Security/Bruteforce/Throttler.php
index 2ee4c23cd1e..5c4f4d320b1 100644
--- a/lib/private/Security/Bruteforce/Throttler.php
+++ b/lib/private/Security/Bruteforce/Throttler.php
@@ -110,7 +110,7 @@ class Throttler implements IThrottler {
* @param string $ip
* @return bool
*/
- private function isIPWhitelisted(string $ip): bool {
+ public function isIPWhitelisted(string $ip): bool {
if (isset($this->ipIsWhitelisted[$ip])) {
return $this->ipIsWhitelisted[$ip];
}
span>"Password to access %1$s was sent to you" : "访问 %1$s 的密码已发送给你", "Password to access {file} was sent to you" : "访问 {file} 的密码已发送给你", "Sharing %s failed, this item is already shared with %s" : "共享 %s 失败, 该项目已经共享于 %s", "%s shared »%s« with you" : "%s 共享 »%s« 与你", "%s shared »%s« with you." : "%s 与你分享分享 »%s« ", "Click the button below to open it." : "点击下面的按钮打开它。", "Open »%s«" : "打开 »%s«", "%s via %s" : "%s通过%s", "Password to access »%s«" : "访问 »%s« 的密码", "This is the password: %s" : "这是密码: %s", "You can choose a different password at any time in the share dialog." : "您可以随时在共享对话框中选择不同的密码。", "Could not find share" : "没有发现共享", "Share by mail" : "通过邮件共享", "Allows users to share a personalized link to a file or folder by putting in an email address." : "允许用户通过电子邮件地址来共享文件或文件夹的个性化链接。", "Send password by mail" : "通过电子邮件发送密码", "Enforce password protection" : "强制密码保护", "Failed to send share by E-mail" : "通过电子邮件发送共享失败", "%s shared »%s« with you on behalf of %s" : "%s 共享 »%s« 和你代表 %s", "Failed to create the E-mail" : "创建电子邮件失败", "Hey there,\n\n%s shared »%s« with you on behalf of %s.\n\n%s\n\n" : "嘿那儿,\n\n%s 共享 »%s« 与你代表 %s.\n\n%s\n\n", "Hey there,\n\n%s shared »%s« with you.\n\n%s\n\n" : "嘿那儿,\n\n%s 共享 »%s« 与你.\n\n%s\n\n", "Cheers!" : "干杯!", "Hey there,<br><br>%s shared <a href=\"%s\">%s</a> with you on behalf of %s.<br><br>" : "嘿那儿,<br><br>%s 共享 <a href=\"%s\">%s</a> 与你代表 %s.<br><br>", "Hey there,<br><br>%s shared <a href=\"%s\">%s</a> with you.<br><br>" : "嘿那儿,<br><br>%s 共享 <a href=\"%s\">%s</a> 与你.<br><br>" },"pluralForm" :"nplurals=1; plural=0;" }