From e041a5f5c113194347e76d4782a52c644aba6d58 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 29 Oct 2020 12:08:23 +1100 Subject: [PATCH] dev/core#2150 Re-enact the recapture validation by validating the response token on recapture Ensure the form rule is actually triggered not just registered --- CRM/Utils/ReCAPTCHA.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CRM/Utils/ReCAPTCHA.php b/CRM/Utils/ReCAPTCHA.php index 14c4272f9d..2764e24264 100644 --- a/CRM/Utils/ReCAPTCHA.php +++ b/CRM/Utils/ReCAPTCHA.php @@ -96,6 +96,7 @@ class CRM_Utils_ReCAPTCHA { TRUE ); $form->registerRule('recaptcha', 'callback', 'validate', 'CRM_Utils_ReCAPTCHA'); + $form->addRule('g-recaptcha-response', ts('Please go back and complete the CAPTCHA at the bottom of this form.'), 'recaptcha'); if ($form->isSubmitted() && empty($form->_submitValues['g-recaptcha-response'])) { $form->setElementError( 'g-recaptcha-response', @@ -117,4 +118,18 @@ class CRM_Utils_ReCAPTCHA { } } + /** + * @param $value + * @param CRM_Core_Form $form + * + * @return mixed + */ + public static function validate($value, $form) { + $resp = recaptcha_check_answer(CRM_Core_Config::singleton()->recaptchaPrivateKey, + $_SERVER['REMOTE_ADDR'], + $_POST['g-recaptcha-response'] + ); + return $resp->is_valid; + } + } -- 2.25.1