From da7723f90680f841747c6fc94c002547f40077f4 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Fri, 29 Jan 2021 15:49:26 +0100 Subject: [PATCH] Add LostPassword Flood Control --- com.woltlab.wcf/objectType.xml | 4 ++++ .../files/lib/form/LostPasswordForm.class.php | 13 +++++++++++++ wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 4 files changed, 19 insertions(+) diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index 59bb5ad52c..b61de04c9d 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -1774,6 +1774,10 @@ com.woltlab.wcf.floodControl + + com.woltlab.wcf.lostPasswordForm + com.woltlab.wcf.floodControl + com.woltlab.wcf.page.controller diff --git a/wcfsetup/install/files/lib/form/LostPasswordForm.class.php b/wcfsetup/install/files/lib/form/LostPasswordForm.class.php index 6dc5b3970a..92d9de2b06 100644 --- a/wcfsetup/install/files/lib/form/LostPasswordForm.class.php +++ b/wcfsetup/install/files/lib/form/LostPasswordForm.class.php @@ -11,6 +11,7 @@ use wcf\system\email\mime\RecipientAwareTextMimePart; use wcf\system\email\UserMailbox; use wcf\system\exception\NamedUserException; use wcf\system\exception\UserInputException; +use wcf\system\flood\FloodControl; use wcf\system\request\LinkHandler; use wcf\system\WCF; use wcf\util\HeaderUtil; @@ -28,6 +29,8 @@ class LostPasswordForm extends AbstractCaptchaForm { const AVAILABLE_DURING_OFFLINE_MODE = true; + private const ALLOWED_RESETS_PER_24H = 5; + /** * username * @var string @@ -73,6 +76,14 @@ class LostPasswordForm extends AbstractCaptchaForm { parent::validate(); + $requests = FloodControl::getInstance()->countContent( + 'com.woltlab.wcf.lostPasswordForm', + new \DateInterval('PT24H') + ); + if ($requests['count'] >= self::ALLOWED_RESETS_PER_24H) { + throw new NamedUserException(WCF::getLanguage()->getDynamicVariable('wcf.user.lostPassword.error.flood')); + } + if (empty($this->username) && empty($this->email)) { throw new UserInputException('username'); } @@ -148,6 +159,8 @@ class LostPasswordForm extends AbstractCaptchaForm $this->saved(); + FloodControl::getInstance()->registerContent('com.woltlab.wcf.lostPasswordForm'); + // forward to index page HeaderUtil::delayedRedirect( LinkHandler::getInstance()->getLink(), diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 22b33d90fd..21822d748e 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -4600,6 +4600,7 @@ Dateianhänge: + getUser()->username}, diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 54042797df..963b8377fe 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -4601,6 +4601,7 @@ Attachments: + getUser()->username}, -- 2.20.1