Skip to content

Commit dae5f03

Browse files
security-package: Added try/catch to Magento\ReCaptchaUi\Model\RequestHandler.php - PayPalObserver fix.
1 parent bd53306 commit dae5f03

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

ReCaptchaPaypal/Observer/PayPalObserver.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use Magento\Framework\Exception\InputException;
1515
use Magento\Framework\Exception\LocalizedException;
1616
use Magento\Framework\Serialize\SerializerInterface;
17-
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
1817
use Magento\ReCaptchaUi\Model\CaptchaResponseResolverInterface;
18+
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface;
1919
use Magento\ReCaptchaUi\Model\ValidationConfigResolverInterface;
2020
use Magento\ReCaptchaValidationApi\Api\ValidatorInterface;
2121
use Psr\Log\LoggerInterface;
@@ -108,19 +108,15 @@ public function execute(Observer $observer): void
108108
try {
109109
$reCaptchaResponse = $this->captchaResponseResolver->resolve($request);
110110
} catch (InputException $e) {
111+
$reCaptchaResponse = null;
111112
$this->logger->error($e);
113+
}
112114

113-
$jsonPayload = $this->serializer->serialize([
114-
'success' => false,
115-
'error' => true,
116-
'error_messages' => $validationConfig->getValidationFailureMessage(),
117-
]);
118-
$response->representJson($jsonPayload);
119-
return;
115+
if (null !== $reCaptchaResponse) {
116+
$validationResult = $this->captchaValidator->isValid($reCaptchaResponse, $validationConfig);
120117
}
121118

122-
$validationResult = $this->captchaValidator->isValid($reCaptchaResponse, $validationConfig);
123-
if (false === $validationResult->isValid()) {
119+
if (null === $reCaptchaResponse || false === $validationResult->isValid()) {
124120
$this->actionFlag->set('', Action::FLAG_NO_DISPATCH, true);
125121

126122
$jsonPayload = $this->serializer->serialize([

0 commit comments

Comments
 (0)