-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(security): Allow to opt-out of ratelimit protection, e.g. for te… #37542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nickvergessen
merged 1 commit into
master
from
bugfix/noid/allow-to-opt-out-of-ratelimit-for-testing
Apr 3, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(security): Allow to opt-out of ratelimit protection, e.g. for te…
…sting on CI Signed-off-by: Joas Schilling <[email protected]>
- Loading branch information
commit 454281af03fb0e917f0135cd6ce51fec5024a0b4
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,8 +3,10 @@ | |
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2023 Joas Schilling <[email protected]> | ||
| * @copyright Copyright (c) 2021 Lukas Reschke <[email protected]> | ||
| * | ||
| * @author Joas Schilling <[email protected]> | ||
| * @author Lukas Reschke <[email protected]> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
|
|
@@ -27,24 +29,25 @@ | |
|
|
||
| use OCP\AppFramework\Utility\ITimeFactory; | ||
| use OCP\DB\QueryBuilder\IQueryBuilder; | ||
| use OCP\IConfig; | ||
| use OCP\IDBConnection; | ||
|
|
||
| class DatabaseBackend implements IBackend { | ||
| private const TABLE_NAME = 'ratelimit_entries'; | ||
|
|
||
| /** @var IConfig */ | ||
| private $config; | ||
| /** @var IDBConnection */ | ||
| private $dbConnection; | ||
| /** @var ITimeFactory */ | ||
| private $timeFactory; | ||
|
|
||
| /** | ||
| * @param IDBConnection $dbConnection | ||
| * @param ITimeFactory $timeFactory | ||
| */ | ||
| public function __construct( | ||
| IConfig $config, | ||
| IDBConnection $dbConnection, | ||
| ITimeFactory $timeFactory | ||
| ) { | ||
| $this->config = $config; | ||
| $this->dbConnection = $dbConnection; | ||
| $this->timeFactory = $timeFactory; | ||
| } | ||
|
|
@@ -115,7 +118,12 @@ public function registerAttempt(string $methodIdentifier, | |
| ->values([ | ||
| 'hash' => $qb->createNamedParameter($identifier, IQueryBuilder::PARAM_STR), | ||
| 'delete_after' => $qb->createNamedParameter($deleteAfter, IQueryBuilder::PARAM_DATE), | ||
| ]) | ||
| ->executeStatement(); | ||
| ]); | ||
|
|
||
| if (!$this->config->getSystemValueBool('ratelimit.protection.enabled', true)) { | ||
| return; | ||
| } | ||
|
|
||
| $qb->executeStatement(); | ||
| } | ||
| } | ||
This file contains hidden or 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 Lukas Reschke <[email protected]> | ||
| * | ||
| * @author Christoph Wurst <[email protected]> | ||
| * @author Joas Schilling <[email protected]> | ||
| * @author Lukas Reschke <[email protected]> | ||
| * @author Morris Jobke <[email protected]> | ||
| * @author Roeland Jago Douma <[email protected]> | ||
|
|
@@ -31,6 +33,7 @@ | |
| use OCP\AppFramework\Utility\ITimeFactory; | ||
| use OCP\ICache; | ||
| use OCP\ICacheFactory; | ||
| use OCP\IConfig; | ||
|
|
||
| /** | ||
| * Class MemoryCacheBackend uses the configured distributed memory cache for storing | ||
|
|
@@ -39,17 +42,18 @@ | |
| * @package OC\Security\RateLimiting\Backend | ||
| */ | ||
| class MemoryCacheBackend implements IBackend { | ||
| /** @var IConfig */ | ||
| private $config; | ||
| /** @var ICache */ | ||
| private $cache; | ||
| /** @var ITimeFactory */ | ||
| private $timeFactory; | ||
|
|
||
| /** | ||
| * @param ICacheFactory $cacheFactory | ||
| * @param ITimeFactory $timeFactory | ||
| */ | ||
| public function __construct(ICacheFactory $cacheFactory, | ||
| ITimeFactory $timeFactory) { | ||
| public function __construct( | ||
| IConfig $config, | ||
| ICacheFactory $cacheFactory, | ||
| ITimeFactory $timeFactory) { | ||
| $this->config = $config; | ||
| $this->cache = $cacheFactory->createDistributed(__CLASS__); | ||
| $this->timeFactory = $timeFactory; | ||
| } | ||
|
|
@@ -121,6 +125,11 @@ public function registerAttempt(string $methodIdentifier, | |
|
|
||
| // Store the new attempt | ||
| $existingAttempts[] = (string)($currentTime + $period); | ||
|
|
||
| if (!$this->config->getSystemValueBool('ratelimit.protection.enabled', true)) { | ||
| return; | ||
| } | ||
|
|
||
| $this->cache->set($identifier, json_encode($existingAttempts)); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.