Skip to content

Commit 1be3c18

Browse files
committed
[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
1 parent da15520 commit 1be3c18

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Classes/Controller/FormController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,17 @@ public function processRequest(RequestInterface $request): ResponseInterface
609609
return parent::processRequest($request);
610610
} catch (PropagateResponseException $e) {
611611
return $e->getResponse();
612+
} catch (BadRequestException $e) {
613+
if (in_array($e->getCode(), [1581862822, 1699604555, 1691267306])) {
614+
// If the trustedProperties HMAC can not be validated, we redirect to an empty form because the
615+
// request cannot be salvaged and would lead to an infinite loop.
616+
$logger = ObjectUtility::getLogger(__CLASS__);
617+
$logger->warning('Redirecting to empty form because HMAC validation failed.', [$e->getMessage()]);
618+
return $this->redirect('form');
619+
}
620+
$logger = ObjectUtility::getLogger(__CLASS__);
621+
$logger->critical('An error occurred: ', [$e->getMessage()]);
622+
return (new ForwardResponse('form'))->withoutArguments();
612623
} catch (\Exception $e) {
613624
$logger = ObjectUtility::getLogger(__CLASS__);
614625
$logger->critical('An error occurred: ', [$e->getMessage()]);

0 commit comments

Comments
 (0)