-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
fix: Add brute force protection to form endpoints
* fix: Add brute force protection to form endpoints Endpoints that query for forms are now protected against brute force attacks to find valid forms, invalid hashes or IDs. --------- Signed-off-by: Ferdinand Thiessen <[email protected]> Signed-off-by: Christian Hartmann <[email protected]> Co-authored-by: Christian Hartmann <[email protected]>
1 parent
04bea4c
commit 6b8fdad
Showing
6 changed files
with
160 additions
and
97 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/*! | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Forms\Exception; | ||
|
||
use OCP\AppFramework\Http; | ||
|
||
class NoSuchFormException extends \Exception { | ||
|
||
public function __construct($message = '', int $errorCode = Http::STATUS_NOT_FOUND) { | ||
parent::__construct($message, $errorCode); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/*! | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Forms\Middleware; | ||
|
||
use Exception; | ||
use OCA\Forms\Exception\NoSuchFormException; | ||
use OCP\AppFramework\Controller; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\Middleware; | ||
|
||
/** | ||
* Simple middleware to throttle requests after invalid form access | ||
*/ | ||
class ThrottleFormAccessMiddleware extends Middleware { | ||
|
||
public function afterException(Controller $controller, string $methodName, Exception $exception) { | ||
if (!($exception instanceof NoSuchFormException)) { | ||
throw $exception; | ||
} | ||
|
||
$response = new DataResponse( | ||
$exception->getMessage(), | ||
$exception->getCode(), | ||
); | ||
$response->throttle(['action' => 'form']); | ||
return $response; | ||
} | ||
} |
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