From e6d787fa732cfd14eb3f45a668ac29b3b0bd9f76 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Wed, 19 Feb 2020 14:02:18 +0200 Subject: [PATCH] security-package/issues/100: Handle CaptchaValidator exception thrown on wrong configuration. --- ReCaptcha/Model/CaptchaValidator.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/ReCaptcha/Model/CaptchaValidator.php b/ReCaptcha/Model/CaptchaValidator.php index 2285f4f0..337e164f 100644 --- a/ReCaptcha/Model/CaptchaValidator.php +++ b/ReCaptcha/Model/CaptchaValidator.php @@ -7,9 +7,9 @@ namespace Magento\ReCaptcha\Model; -use Magento\Framework\Exception\LocalizedException; use Magento\ReCaptchaApi\Api\CaptchaValidatorInterface; use Magento\ReCaptchaApi\Api\Data\ValidationConfigInterface; +use Psr\Log\LoggerInterface; use ReCaptcha\ReCaptcha; /** @@ -17,6 +17,19 @@ */ class CaptchaValidator implements CaptchaValidatorInterface { + /** + * @var LoggerInterface + */ + private $logger; + + /** + * @param LoggerInterface $logger + */ + public function __construct(LoggerInterface $logger) + { + $this->logger = $logger; + } + /** * @inheritdoc */ @@ -24,6 +37,7 @@ public function validate( string $reCaptchaResponse, ValidationConfigInterface $validationConfig ): bool { + $result = false; $secret = $validationConfig->getPrivateKey(); if ($reCaptchaResponse) { @@ -39,14 +53,12 @@ public function validate( $res = $reCaptcha->verify($reCaptchaResponse, $validationConfig->getRemoteIp()); if (($validationConfig->getCaptchaType() === 'recaptcha_v3') && ($res->getScore() === null)) { - throw new LocalizedException(__('Internal error: Make sure you are using reCaptcha V3 api keys')); - } - - if ($res->isSuccess()) { - return true; + $this->logger->alert(__('Internal error: Make sure you are using reCaptcha V3 api keys')); + } else if ($res->isSuccess()) { + $result = true; } } - return false; + return $result; } }