-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Expose if the own IP is allowed to bypass bruteforce protection
Signed-off-by: Joas Schilling <[email protected]>
- Loading branch information
1 parent
754afda
commit a326817
Showing
3 changed files
with
23 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ | |
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2023 Joas Schilling <[email protected]> | ||
* @copyright Copyright (c) 2017 Roeland Jago Douma <[email protected]> | ||
* | ||
* @author J0WI <[email protected]> | ||
* @author Joas Schilling <[email protected]> | ||
* @author Julius Härtl <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* | ||
|
@@ -32,33 +34,21 @@ | |
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()), | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters