Skip to content

Commit 192d8a5

Browse files
authored
[BUGFIX] Prevent infinite loop when trustedProperties validation fails (#1294)
* [BUGFIX] Prevent infinite loop when trustedProperties validation fails If the __trustedProperties hidden property of a form is manipulated or submit as empty, the HMAC validation fails, throwing an exception. The normal exception handling then tries to forward the request to the formAction, which itself also validates the HMAC. This leads to an infinite loop which is only resolved after 100 iterations by throwing an InfiniteLoopException. This process takes time, therefore Powermail is vulnerable to DoS attacks. The change checks for a BadRequestException from the HMAC validation. In such a case, a redirect to the (then empty) formAction is performed and the error is logged. Resolves: #1293 * fix: Add BadRequestException import to FormController
1 parent da15520 commit 192d8a5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Classes/Controller/FormController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use In2code\Powermail\Utility\ObjectUtility;
3939
use In2code\Powermail\Utility\SessionUtility;
4040
use In2code\Powermail\Utility\TemplateUtility;
41+
use TYPO3\CMS\Core\Error\Http\BadRequestException;
4142
use function in_array;
4243
use Psr\EventDispatcher\EventDispatcherInterface;
4344
use Psr\Http\Message\ResponseInterface;
@@ -609,6 +610,17 @@ public function processRequest(RequestInterface $request): ResponseInterface
609610
return parent::processRequest($request);
610611
} catch (PropagateResponseException $e) {
611612
return $e->getResponse();
613+
} catch (BadRequestException $e) {
614+
if (in_array($e->getCode(), [1581862822, 1699604555, 1691267306])) {
615+
// If the trustedProperties HMAC can not be validated, we redirect to an empty form because the
616+
// request cannot be salvaged and would lead to an infinite loop.
617+
$logger = ObjectUtility::getLogger(__CLASS__);
618+
$logger->warning('Redirecting to empty form because HMAC validation failed.', [$e->getMessage()]);
619+
return $this->redirect('form');
620+
}
621+
$logger = ObjectUtility::getLogger(__CLASS__);
622+
$logger->critical('An error occurred: ', [$e->getMessage()]);
623+
return (new ForwardResponse('form'))->withoutArguments();
612624
} catch (\Exception $e) {
613625
$logger = ObjectUtility::getLogger(__CLASS__);
614626
$logger->critical('An error occurred: ', [$e->getMessage()]);

0 commit comments

Comments
 (0)