Skip to content

A free open source IT asset/license management system

Throttle TOTP requests

snipe46d5234fd73d
diff --git a/.env.example b/.env.example
index 75ac7fe3d0..187de61b36 100644
--- a/.env.example
+++ b/.env.example
@@ -210,6 +210,7 @@ LOGIN_AUTOCOMPLETE=false
RESET_PASSWORD_LINK_EXPIRES=15
PASSWORD_CONFIRM_TIMEOUT=10800
PASSWORD_RESET_MAX_ATTEMPTS_PER_MIN=50
+TWO_FACTOR_MAX_ATTEMPTS_PER_MIN=5
INVITE_PASSWORD_LINK_EXPIRES=1500
# --------------------------------------------
diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php
index e8b3c33f6e..bccde92d03 100644
--- a/app/Providers/RouteServiceProvider.php
+++ b/app/Providers/RouteServiceProvider.php
@@ -103,5 +103,11 @@ class RouteServiceProvider extends ServiceProvider
return Limit::perMinute(config('auth.password_reset.max_attempts_per_min'))->by(optional($request->user())->id ?: $request->ip());
});
+ // Rate limiter for two-factor authentication — keyed on user ID since the user is already
+ // password-authenticated at this stage, preventing distributed brute force across IPs.
+ RateLimiter::for('two_factor', function (Request $request) {
+ return Limit::perMinute(config('auth.two_factor.max_attempts_per_min'))->by(optional($request->user())->id ?: $request->ip());
+ });
+
}
}
diff --git a/config/auth.php b/config/auth.php
index 4d090ee9dd..ad771e5896 100644
--- a/config/auth.php
+++ b/config/auth.php
@@ -122,6 +122,10 @@ return [
'max_attempts_per_min' => env('PASSWORD_RESET_MAX_ATTEMPTS_PER_MIN', 50),
],
+ 'two_factor' => [
+ 'max_attempts_per_min' => env('TWO_FACTOR_MAX_ATTEMPTS_PER_MIN', 5),
+ ],
+
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
diff --git a/routes/web.php b/routes/web.php
index 6ec0bc1982..f2f9be664e 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -655,7 +655,7 @@ Route::group(['middleware' => 'web'], function () {
Route::post(
'two-factor',
[LoginController::class, 'postTwoFactorAuth']
- );
+ )->middleware('throttle:two_factor');
Route::post(
'password/email',