Skip to content

Commit 3b040d2

Browse files
committed
[BUGFIX] Prevent too many iteration exception
By using a special exception the custom process request, the dispatching of requests can be intercepted. The request is then redirected to a new and empty form. Related: #1372
1 parent 7c7005f commit 3b040d2

4 files changed

Lines changed: 120 additions & 51 deletions

File tree

‎.project/tests/phpstan-baseline.neon‎

Lines changed: 79 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ parameters:
66
count: 1
77
path: ../../Classes/Command/AbstractCleanupCommand.php
88

9+
-
10+
message: '#^Call to an undefined method object\:\:getValue\(\)\.$#'
11+
identifier: method.notFound
12+
count: 1
13+
path: ../../Classes/Command/CleanupUnusedUploadsCommand.php
14+
915
-
1016
message: '#^Method In2code\\Powermail\\Command\\CleanupUnusedUploadsCommand\:\:getUsedUploads\(\) return type has no value type specified in iterable type array\.$#'
1117
identifier: missingType.iterableValue
@@ -295,13 +301,13 @@ parameters:
295301
path: ../../Classes/Domain/Factory/FileFactory.php
296302

297303
-
298-
message: '#^Cannot call method getUid\(\) on In2code\\Powermail\\Domain\\Model\\Form\|TYPO3\\CMS\\Extbase\\Persistence\\Generic\\LazyLoadingProxy\|null\.$#'
299-
identifier: method.nonObject
304+
message: '#^Call to an undefined method object\:\:setPid\(\)\.$#'
305+
identifier: method.notFound
300306
count: 1
301307
path: ../../Classes/Domain/Factory/MailFactory.php
302308

303309
-
304-
message: '#^Cannot call method setPid\(\) on object\|null\.$#'
310+
message: '#^Cannot call method getUid\(\) on In2code\\Powermail\\Domain\\Model\\Form\|TYPO3\\CMS\\Extbase\\Persistence\\Generic\\LazyLoadingProxy\|null\.$#'
305311
identifier: method.nonObject
306312
count: 1
307313
path: ../../Classes/Domain/Factory/MailFactory.php
@@ -936,6 +942,12 @@ parameters:
936942
count: 1
937943
path: ../../Classes/Domain/Repository/MailRepository.php
938944

945+
-
946+
message: '#^Call to an undefined method object\:\:getField\(\)\.$#'
947+
identifier: method.notFound
948+
count: 2
949+
path: ../../Classes/Domain/Repository/MailRepository.php
950+
939951
-
940952
message: '#^Call to an undefined method object\:\:getForm\(\)\.$#'
941953
identifier: method.notFound
@@ -955,33 +967,27 @@ parameters:
955967
path: ../../Classes/Domain/Repository/MailRepository.php
956968

957969
-
958-
message: '#^Call to an undefined method object\:\:getValue\(\)\.$#'
970+
message: '#^Call to an undefined method object\:\:getUid\(\)\.$#'
959971
identifier: method.notFound
960-
count: 1
961-
path: ../../Classes/Domain/Repository/MailRepository.php
962-
963-
-
964-
message: '#^Cannot call method getField\(\) on object\|null\.$#'
965-
identifier: method.nonObject
966972
count: 2
967973
path: ../../Classes/Domain/Repository/MailRepository.php
968974

969975
-
970-
message: '#^Cannot call method getMarker\(\) on class\-string\|object\.$#'
971-
identifier: method.nonObject
976+
message: '#^Call to an undefined method object\:\:getValue\(\)\.$#'
977+
identifier: method.notFound
972978
count: 3
973979
path: ../../Classes/Domain/Repository/MailRepository.php
974980

975981
-
976-
message: '#^Cannot call method getTitle\(\) on class\-string\|object\.$#'
982+
message: '#^Cannot call method getMarker\(\) on class\-string\|object\.$#'
977983
identifier: method.nonObject
978984
count: 1
979985
path: ../../Classes/Domain/Repository/MailRepository.php
980986

981987
-
982-
message: '#^Cannot call method getValue\(\) on object\|null\.$#'
988+
message: '#^Cannot call method getTitle\(\) on class\-string\|object\.$#'
983989
identifier: method.nonObject
984-
count: 2
990+
count: 1
985991
path: ../../Classes/Domain/Repository/MailRepository.php
986992

987993
-
@@ -1152,12 +1158,6 @@ parameters:
11521158
count: 1
11531159
path: ../../Classes/Domain/Repository/MailRepository.php
11541160

1155-
-
1156-
message: '#^Parameter \#1 \$object_or_class of function method_exists expects object\|string, object\|null given\.$#'
1157-
identifier: argument.type
1158-
count: 2
1159-
path: ../../Classes/Domain/Repository/MailRepository.php
1160-
11611161
-
11621162
message: '#^Parameter \#2 \$formUid of method In2code\\Powermail\\Domain\\Repository\\FieldRepository\:\:findByMarkerAndForm\(\) expects int, int\<1, max\>\|null given\.$#'
11631163
identifier: argument.type
@@ -2323,8 +2323,8 @@ parameters:
23232323
path: ../../Classes/Domain/Validator/SpamShield/Breaker/IpBreaker.php
23242324

23252325
-
2326-
message: '#^Cannot call method getValue\(\) on object\|null\.$#'
2327-
identifier: method.nonObject
2326+
message: '#^Call to an undefined method object\:\:getValue\(\)\.$#'
2327+
identifier: method.notFound
23282328
count: 1
23292329
path: ../../Classes/Domain/Validator/SpamShield/Breaker/ValueBreaker.php
23302330

@@ -2347,8 +2347,8 @@ parameters:
23472347
path: ../../Classes/Domain/Validator/SpamShield/IpBlacklistMethod.php
23482348

23492349
-
2350-
message: '#^Cannot call method getValue\(\) on object\|null\.$#'
2351-
identifier: method.nonObject
2350+
message: '#^Call to an undefined method object\:\:getValue\(\)\.$#'
2351+
identifier: method.notFound
23522352
count: 2
23532353
path: ../../Classes/Domain/Validator/SpamShield/LinkMethod.php
23542354

@@ -2371,14 +2371,14 @@ parameters:
23712371
path: ../../Classes/Domain/Validator/SpamShield/MethodInterface.php
23722372

23732373
-
2374-
message: '#^Cannot call method getField\(\) on object\|null\.$#'
2375-
identifier: method.nonObject
2374+
message: '#^Call to an undefined method object\:\:getField\(\)\.$#'
2375+
identifier: method.notFound
23762376
count: 2
23772377
path: ../../Classes/Domain/Validator/SpamShield/NameMethod.php
23782378

23792379
-
2380-
message: '#^Cannot call method getValue\(\) on object\|null\.$#'
2381-
identifier: method.nonObject
2380+
message: '#^Call to an undefined method object\:\:getValue\(\)\.$#'
2381+
identifier: method.notFound
23822382
count: 3
23832383
path: ../../Classes/Domain/Validator/SpamShield/NameMethod.php
23842384

@@ -2401,8 +2401,8 @@ parameters:
24012401
path: ../../Classes/Domain/Validator/SpamShield/SessionMethod.php
24022402

24032403
-
2404-
message: '#^Cannot call method getValue\(\) on object\|null\.$#'
2405-
identifier: method.nonObject
2404+
message: '#^Call to an undefined method object\:\:getValue\(\)\.$#'
2405+
identifier: method.notFound
24062406
count: 3
24072407
path: ../../Classes/Domain/Validator/SpamShield/UniqueMethod.php
24082408

@@ -2478,6 +2478,24 @@ parameters:
24782478
count: 1
24792479
path: ../../Classes/Domain/Validator/SpamShieldValidator.php
24802480

2481+
-
2482+
message: '#^Result of && is always true\.$#'
2483+
identifier: booleanAnd.alwaysTrue
2484+
count: 1
2485+
path: ../../Classes/Domain/Validator/StringValidator.php
2486+
2487+
-
2488+
message: '#^Strict comparison using \!\=\= between non\-falsy\-string and '''' will always evaluate to true\.$#'
2489+
identifier: notIdentical.alwaysTrue
2490+
count: 1
2491+
path: ../../Classes/Domain/Validator/StringValidator.php
2492+
2493+
-
2494+
message: '#^Strict comparison using \!\=\= between non\-falsy\-string and ''0'' will always evaluate to true\.$#'
2495+
identifier: notIdentical.alwaysTrue
2496+
count: 1
2497+
path: ../../Classes/Domain/Validator/StringValidator.php
2498+
24812499
-
24822500
message: '#^Cannot call method getMarker\(\) on In2code\\Powermail\\Domain\\Model\\Field\|null\.$#'
24832501
identifier: method.nonObject
@@ -3819,13 +3837,7 @@ parameters:
38193837
-
38203838
message: '#^Method In2code\\Powermail\\Utility\\ReportingUtility\:\:getGroupedAnswersFromMails\(\) has parameter \$mails with no value type specified in iterable type iterable\<\(int\|string\), mixed\>\.$#'
38213839
identifier: missingType.iterableValue
3822-
count: 1
3823-
path: ../../Classes/Utility/ReportingUtility.php
3824-
3825-
-
3826-
message: '#^Method In2code\\Powermail\\Utility\\ReportingUtility\:\:getGroupedAnswersFromMails\(\) has parameter \$mails with no value type specified in iterable type iterable\<\(int\|string\), mixed\>\|TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface\.$#'
3827-
identifier: missingType.iterableValue
3828-
count: 1
3840+
count: 2
38293841
path: ../../Classes/Utility/ReportingUtility.php
38303842

38313843
-
@@ -3843,13 +3855,7 @@ parameters:
38433855
-
38443856
message: '#^Method In2code\\Powermail\\Utility\\ReportingUtility\:\:getGroupedMarketingPropertiesFromMails\(\) has parameter \$mails with no value type specified in iterable type iterable\<\(int\|string\), mixed\>\.$#'
38453857
identifier: missingType.iterableValue
3846-
count: 1
3847-
path: ../../Classes/Utility/ReportingUtility.php
3848-
3849-
-
3850-
message: '#^Method In2code\\Powermail\\Utility\\ReportingUtility\:\:getGroupedMarketingPropertiesFromMails\(\) has parameter \$mails with no value type specified in iterable type iterable\<\(int\|string\), mixed\>\|TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface\.$#'
3851-
identifier: missingType.iterableValue
3852-
count: 1
3858+
count: 2
38533859
path: ../../Classes/Utility/ReportingUtility.php
38543860

38553861
-
@@ -3966,6 +3972,12 @@ parameters:
39663972
count: 1
39673973
path: ../../Classes/Utility/StringUtility.php
39683974

3975+
-
3976+
message: '#^Offset 1 might not exist on array\{\}\|array\{non\-falsy\-string, string\}\.$#'
3977+
identifier: offsetAccess.notFound
3978+
count: 1
3979+
path: ../../Classes/Utility/StringUtility.php
3980+
39693981
-
39703982
message: '#^Method In2code\\Powermail\\Utility\\TemplateUtility\:\:fluidParseString\(\) has parameter \$variables with no value type specified in iterable type array\.$#'
39713983
identifier: missingType.iterableValue
@@ -4098,6 +4110,18 @@ parameters:
40984110
count: 1
40994111
path: ../../Classes/ViewHelpers/Condition/IsThereAMailWithStartingLetterViewHelper.php
41004112

4113+
-
4114+
message: '#^Result of && is always false\.$#'
4115+
identifier: booleanAnd.alwaysFalse
4116+
count: 1
4117+
path: ../../Classes/ViewHelpers/Condition/OrViewHelper.php
4118+
4119+
-
4120+
message: '#^Strict comparison using \=\=\= between 0\|0\.0\|''''\|''0''\|array\{\}\|false\|null and mixed will always evaluate to false\.$#'
4121+
identifier: identical.alwaysFalse
4122+
count: 1
4123+
path: ../../Classes/ViewHelpers/Condition/OrViewHelper.php
4124+
41014125
-
41024126
message: '#^Cannot cast object to string\.$#'
41034127
identifier: cast.string
@@ -4495,14 +4519,20 @@ parameters:
44954519
path: ../../Classes/ViewHelpers/Misc/PrefillFieldViewHelper.php
44964520

44974521
-
4498-
message: '#^Cannot call method getField\(\) on object\|null\.$#'
4499-
identifier: method.nonObject
4522+
message: '#^Strict comparison using \!\=\= between object and null will always evaluate to true\.$#'
4523+
identifier: notIdentical.alwaysTrue
4524+
count: 1
4525+
path: ../../Classes/ViewHelpers/Misc/PrefillFieldViewHelper.php
4526+
4527+
-
4528+
message: '#^Call to an undefined method object\:\:getField\(\)\.$#'
4529+
identifier: method.notFound
45004530
count: 1
45014531
path: ../../Classes/ViewHelpers/Misc/PrefillMultiFieldViewHelper.php
45024532

45034533
-
4504-
message: '#^Cannot call method getValue\(\) on object\|null\.$#'
4505-
identifier: method.nonObject
4534+
message: '#^Call to an undefined method object\:\:getValue\(\)\.$#'
4535+
identifier: method.notFound
45064536
count: 1
45074537
path: ../../Classes/ViewHelpers/Misc/PrefillMultiFieldViewHelper.php
45084538

‎Classes/Controller/FormController.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use In2code\Powermail\Events\FormControllerOptinConfirmActionAfterPersistEvent;
3131
use In2code\Powermail\Events\FormControllerOptinConfirmActionBeforeRenderViewEvent;
3232
use In2code\Powermail\Exception\DeprecatedException;
33+
use In2code\Powermail\Exception\SpamDetectedException;
3334
use In2code\Powermail\Finisher\FinisherRunner;
3435
use In2code\Powermail\Utility\ConfigurationUtility;
3536
use In2code\Powermail\Utility\DatabaseUtility;
@@ -611,16 +612,20 @@ public function processRequest(RequestInterface $request): ResponseInterface
611612
} catch (PropagateResponseException $e) {
612613
return $e->getResponse();
613614
} catch (BadRequestException $e) {
615+
$logger = ObjectUtility::getLogger(__CLASS__);
614616
if (in_array($e->getCode(), [1581862822, 1699604555, 1691267306])) {
615617
// If the trustedProperties HMAC can not be validated, we redirect to an empty form because the
616618
// request cannot be salvaged and would lead to an infinite loop.
617-
$logger = ObjectUtility::getLogger(__CLASS__);
618619
$logger->warning('Redirecting to empty form because HMAC validation failed.', [$e->getMessage()]);
619620
return $this->redirect('form');
620621
}
621-
$logger = ObjectUtility::getLogger(__CLASS__);
622622
$logger->critical('An error occurred: ', [$e->getMessage()]);
623623
return (new ForwardResponse('form'))->withoutArguments();
624+
} catch (SpamDetectedException $e) {
625+
// Catch "Could not ultimately dispatch the request after 101 iterations" within spamshield
626+
$logger = ObjectUtility::getLogger(__CLASS__);
627+
$logger->critical('SPAM detected: ', [$e->getMessage()]);
628+
return $this->redirect('form');
624629
} catch (\Exception $e) {
625630
$logger = ObjectUtility::getLogger(__CLASS__);
626631
$logger->critical('An error occurred: ', [$e->getMessage()]);

‎Classes/Domain/Validator/SpamShieldValidator.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use In2code\Powermail\Domain\Validator\SpamShield\MethodInterface;
1111
use In2code\Powermail\Exception\ClassDoesNotExistException;
1212
use In2code\Powermail\Exception\InterfaceNotImplementedException;
13+
use In2code\Powermail\Exception\SpamDetectedException;
1314
use In2code\Powermail\Utility\BasicFileUtility;
1415
use In2code\Powermail\Utility\ConfigurationUtility;
1516
use In2code\Powermail\Utility\FrontendUtility;
@@ -77,6 +78,13 @@ protected function isValid($mail): void
7778
$this->setValidState(false);
7879
$this->sendSpamNotificationMail($mail);
7980
$this->logSpamNotification($mail);
81+
throw new SpamDetectedException(
82+
'Powermail: Spam tolerance limit reached;'
83+
. '; value: ' . $this->getCalculatedSpamFactor(true)
84+
. '; form: ' . $mail->getForm()->getUid()
85+
. ' on page: ' . $mail->getForm()->getPid(),
86+
1784729722
87+
);
8088
}
8189
}
8290

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace In2code\Powermail\Exception;
4+
5+
use TYPO3\CMS\Core\Error\Http\AbstractClientErrorException;
6+
use TYPO3\CMS\Core\Utility\HttpUtility;
7+
8+
class SpamDetectedException extends AbstractClientErrorException
9+
{
10+
/**
11+
* @var array<string> HTTP Status Header lines
12+
*/
13+
protected $statusHeaders = [HttpUtility::HTTP_STATUS_406];
14+
15+
protected $title = 'Spam Detected';
16+
17+
protected $message = 'The request cannot be fulfilled due to detected spam.';
18+
19+
public function __construct($message = null, $code = 0)
20+
{
21+
if (!empty($message)) {
22+
$this->message = $message;
23+
}
24+
parent::__construct($this->statusHeaders, $this->message, $this->title, $code);
25+
}
26+
}

0 commit comments

Comments
 (0)