Skip to content

Commit

Permalink
fix: Add rate limiting for login and forgot password routes
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Feb 21, 2024
1 parent 2b76f41 commit 5e50ed5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
24 changes: 9 additions & 15 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Providers;

use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;

/**
Expand All @@ -28,7 +30,13 @@ class RouteServiceProvider extends ServiceProvider
*/
public function boot()
{
//
RateLimiter::for('login', function ($request) {
return Limit::perMinute(3)->by($request->email.$request->ip());
});

RateLimiter::for('forgot-password', function ($request) {
return Limit::perMinutes(5, 2)->by($request->email.$request->ip());
});

parent::boot();
}
Expand Down Expand Up @@ -73,18 +81,4 @@ protected function mapWebRoutes()
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}

/**
* Map extension developer routes
*
* This function registers extra routes that is coming from extension developer mode
*
* @return void
*/
protected function mapExtensionDeveloperRoutes()
{
Route::namespace($this->namespace)
->middleware('web')
->group(base_path('routes/extension_developer.php'));
}
}
4 changes: 2 additions & 2 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
'prefix' => 'auth'
], function () {
Route::post('/login', [AuthController::class, 'login'])
->middleware('throttle:5,2');
->middleware('throttle:login');
Route::post('/setup_mfa', [AuthController::class, 'setupTwoFactorAuthentication']);
Route::post('/logout', [AuthController::class, 'logout']);
Route::get('/user', [AuthController::class, 'userProfile']);
Route::post('/change_password', [AuthController::class, 'forceChangePassword']);
Route::post('/forgot_password', [AuthController::class, 'sendPasswordResetLink'])
->middleware('throttle:5,15');
->middleware('throttle:forgot-password');
Route::post('/reset_password', [AuthController::class, 'resetPassword']);
});

Expand Down

0 comments on commit 5e50ed5

Please sign in to comment.