From e0afebaf057aea0109fd2d8d2dadcfca1bcc50ad Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 15 Jun 2021 07:58:12 +0200 Subject: [PATCH] Remove deprecated Recaptcha-related classes (#4289) See #4281 --- com.woltlab.wcf/fileDelete.xml | 2 + .../files/lib/form/RecaptchaForm.class.php | 108 ------------------ .../recaptcha/RecaptchaHandlerV2.class.php | 77 ------------- 3 files changed, 2 insertions(+), 185 deletions(-) delete mode 100644 wcfsetup/install/files/lib/form/RecaptchaForm.class.php delete mode 100644 wcfsetup/install/files/lib/system/recaptcha/RecaptchaHandlerV2.class.php diff --git a/com.woltlab.wcf/fileDelete.xml b/com.woltlab.wcf/fileDelete.xml index 0c7e67556e..62c5ad9250 100644 --- a/com.woltlab.wcf/fileDelete.xml +++ b/com.woltlab.wcf/fileDelete.xml @@ -1320,6 +1320,7 @@ lib/form/AbstractSecureForm.class.php lib/form/MailForm.class.php lib/form/MultifactorAuthenticationAbortForm.class.php + lib/form/RecaptchaForm.class.php lib/page/CookiePolicyPage.class.php lib/page/DashboardPage.class.php lib/page/LessStylesheetsPage.class.php @@ -1855,6 +1856,7 @@ lib/system/page/location/IPageLocation.class.php lib/system/payment/method/SofortUeberweisungPaymentMethod.class.php lib/system/recaptcha/RecaptchaHandler.class.php + lib/system/recaptcha/RecaptchaHandlerV2.class.php lib/system/request/CmsLinkHandler.class.php lib/system/request/FlexibleRoute.class.php lib/system/request/IRoute.class.php diff --git a/wcfsetup/install/files/lib/form/RecaptchaForm.class.php b/wcfsetup/install/files/lib/form/RecaptchaForm.class.php deleted file mode 100644 index 1c8c3a7163..0000000000 --- a/wcfsetup/install/files/lib/form/RecaptchaForm.class.php +++ /dev/null @@ -1,108 +0,0 @@ - - * @package WoltLabSuite\Core\Form - * @deprecated 2.1 - */ -abstract class RecaptchaForm extends AbstractForm -{ - /** - * challenge - * @var string - */ - public $challenge = ''; - - /** - * response - * @var string - */ - public $response = ''; - - /** - * enable recaptcha - * @var bool - */ - public $useCaptcha = true; - - /** - * @inheritDoc - */ - public function readParameters() - { - parent::readParameters(); - - if (WCF::getUser()->userID || WCF::getSession()->getVar('recaptchaDone')) { - $this->useCaptcha = false; - } - } - - /** - * @inheritDoc - */ - public function readFormParameters() - { - parent::readFormParameters(); - - if (isset($_POST['g-recaptcha-response'])) { - $this->response = $_POST['g-recaptcha-response']; - } - } - - /** - * @inheritDoc - */ - public function validate() - { - parent::validate(); - - $this->validateCaptcha(); - } - - /** - * Validates the captcha. - */ - protected function validateCaptcha() - { - if ($this->useCaptcha) { - RecaptchaHandlerV2::getInstance()->validate($this->response); - - $this->useCaptcha = false; - } - } - - /** - * @inheritDoc - */ - public function save() - { - parent::save(); - - WCF::getSession()->unregister('recaptchaDone'); - } - - /** - * @inheritDoc - */ - public function assignVariables() - { - parent::assignVariables(); - - WCF::getTPL()->assign([ - 'recaptchaLegacyMode' => true, - ]); - - WCF::getTPL()->assign([ - 'useCaptcha' => $this->useCaptcha, - ]); - } -} diff --git a/wcfsetup/install/files/lib/system/recaptcha/RecaptchaHandlerV2.class.php b/wcfsetup/install/files/lib/system/recaptcha/RecaptchaHandlerV2.class.php deleted file mode 100644 index dd3b430193..0000000000 --- a/wcfsetup/install/files/lib/system/recaptcha/RecaptchaHandlerV2.class.php +++ /dev/null @@ -1,77 +0,0 @@ - - * @package WoltLabSuite\Core\System\Recaptcha - * @deprecated 5.4 - This was an implementation detail of wcf\system\captcha\RecaptchaHandler. - */ -class RecaptchaHandlerV2 extends SingletonFactory -{ - /** - * Validates response. - * - * @param string $response - * @param string $type - * @throws UserInputException - */ - public function validate($response, $type = 'v2') - { - // fail if response is empty to avoid sending api requests - if (empty($response)) { - throw new UserInputException('recaptchaString', 'false'); - } - - if ($type === 'v2') { - $key = RECAPTCHA_PRIVATEKEY; - } elseif ($type === 'invisible') { - $key = RECAPTCHA_PRIVATEKEY_INVISIBLE; - } else { - // The bot modified the `recaptcha-type` form field. - throw new UserInputException('recaptchaString', 'false'); - } - - $request = new HTTPRequest( - \sprintf( - 'https://www.google.com/recaptcha/api/siteverify?secret=%s&response=%s&remoteip=%s', - \rawurlencode($key), - \rawurlencode($response), - \rawurlencode(UserUtil::getIpAddress()) - ), - ['timeout' => 10] - ); - - try { - $request->execute(); - $reply = $request->getReply(); - $data = JSON::decode($reply['body']); - - if ($data['success']) { - // yeah - } else { - throw new UserInputException('recaptchaString', 'false'); - } - } catch (\Exception $e) { - if ($e instanceof UserInputException) { - throw $e; - } - - // log error, but accept captcha - \wcf\functions\exception\logThrowable($e); - } - - WCF::getSession()->register('recaptchaDone', true); - } -} -- 2.20.1