diff --git a/Classes/Controller/FormController.php b/Classes/Controller/FormController.php index 8329f2ae1..958cd33ef 100644 --- a/Classes/Controller/FormController.php +++ b/Classes/Controller/FormController.php @@ -38,6 +38,7 @@ use In2code\Powermail\Utility\ObjectUtility; use In2code\Powermail\Utility\SessionUtility; use In2code\Powermail\Utility\TemplateUtility; +use TYPO3\CMS\Core\Error\Http\BadRequestException; use function in_array; use Psr\EventDispatcher\EventDispatcherInterface; use Psr\Http\Message\ResponseInterface; @@ -609,6 +610,17 @@ public function processRequest(RequestInterface $request): ResponseInterface return parent::processRequest($request); } catch (PropagateResponseException $e) { return $e->getResponse(); + } catch (BadRequestException $e) { + if (in_array($e->getCode(), [1581862822, 1699604555, 1691267306])) { + // If the trustedProperties HMAC can not be validated, we redirect to an empty form because the + // request cannot be salvaged and would lead to an infinite loop. + $logger = ObjectUtility::getLogger(__CLASS__); + $logger->warning('Redirecting to empty form because HMAC validation failed.', [$e->getMessage()]); + return $this->redirect('form'); + } + $logger = ObjectUtility::getLogger(__CLASS__); + $logger->critical('An error occurred: ', [$e->getMessage()]); + return (new ForwardResponse('form'))->withoutArguments(); } catch (\Exception $e) { $logger = ObjectUtility::getLogger(__CLASS__); $logger->critical('An error occurred: ', [$e->getMessage()]);