Skip to content

Commit 8397642

Browse files
authored
Refactor password reset rate limiting methods
1 parent c8f699b commit 8397642

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

application/modules/sessions/controllers/Sessions.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ public function passwordreset($token = null)
197197
}
198198

199199
// Security: Check IP-based rate limiting first (prevents email enumeration)
200-
if ($this->_is_ip_rate_limited_password_reset(env('PASSWORD_RESET_IP_MAX_ATTEMPTS', 5), env('PASSWORD_RESET_IP_WINDOW_MINUTES', 60))) {
200+
if ($this->_is_ip_rate_limited_password_reset() {
201201
log_message('warning', trans('log_password_reset_ip_rate_limit') . ' from: ' . $this->input->ip_address());
202202
redirect('sessions/login');
203203
}
204204

205205
// Security: Prevent brute force attacks by counting password reset attempts per email
206-
if ($this->_is_email_rate_limited_password_reset($email, env('PASSWORD_RESET_EMAIL_MAX_ATTEMPTS', 3), env('PASSWORD_RESET_EMAIL_WINDOW_HOURS', 1))) {
206+
if ($this->_is_email_rate_limited_password_reset($email) {
207207
log_message('warning', trans('log_password_reset_email_rate_limit') . ' for: ' . $email . ' from IP: ' . $this->input->ip_address());
208208
redirect('sessions/login');
209209
}
@@ -328,8 +328,11 @@ private function _login_log_check($username)
328328
*
329329
* @return bool True if rate limited, false otherwise
330330
*/
331-
private function _is_ip_rate_limited_password_reset($max_attempts, $window_minutes)
331+
private function _is_ip_rate_limited_password_reset()
332332
{
333+
$attempts = env('PASSWORD_RESET_EMAIL_MAX_ATTEMPTS', 3),
334+
$window_minutes = env('PASSWORD_RESET_EMAIL_WINDOW_HOURS', 1))
335+
333336
$ip_address = $this->input->ip_address();
334337
$session_key = 'password_reset_attempts_' . md5($ip_address);
335338

@@ -386,8 +389,11 @@ private function _record_password_reset_attempt()
386389
*
387390
* @return bool True if rate limited, false otherwise
388391
*/
389-
private function _is_email_rate_limited_password_reset($email, $max_attempts, $window_hours)
392+
private function _is_email_rate_limited_password_reset($email)
390393
{
394+
$attempts = env('PASSWORD_RESET_EMAIL_MAX_ATTEMPTS', 3),
395+
$window_minutes = env('PASSWORD_RESET_EMAIL_WINDOW_HOURS', 1))
396+
391397
$session_key = 'password_reset_email_' . md5($email);
392398

393399
// Get current attempts from session

0 commit comments

Comments
 (0)