-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed issue with login throttle condition and conflict with Laravel middleware #547
Fixed issue with login throttle condition and conflict with Laravel middleware #547
Conversation
I don't agree that anything needs to be changed here. |
@taylorotwell - OK. I'll try my best to defend the point here with facts. The current code have one config ( Finally, we have one config option that is mutually exclusive. If I set the You have to agree that at minimum it is misleading and lacks a lot of clarification. You can see that through multiple issues already reported in the past. I pointed some of them here with 5 min searching. There are threads in many websites about it. |
No, I don't agree it is confusing. You only set `login` => 'the-name-of-my-rate-limiter` |
@taylorotwell - I'm not confused about that. I might not be doing a good job communicating this because I feel you're hundreds of miles away from the point of my PR. The point is when and how can Fortify's throttle system (verified here: Anyway. I tried. Feel free to close this PR if you still don't agree. I have solved it on my end. Regardless of the disagreement, awesome package, great community, good job with the eco-system of Laravel. |
Upon investigating on this yes @taylorotwell is correct on the matter. The value of `login` => 'the-name-of-my-rate-limiter` Which later then you can define the rate limiter in your service provider such as: RateLimiter::for('the-name-of-my-rate-limiter', function (Request $request) {
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->IP());
return Limit::perMinute(5)->by($throttleKey);
}); fortify/stubs/FortifyServiceProvider.php Lines 36 to 40 in 5c2e9cd
|
@taylorotwell @crynobone - thanks for taking the time to review and for the input. Closing the PR. |
Overview
This change will fix an issue where the
EnsureLoginIsNotThrottled
verification is never reached iffortify.limiters.login
has any value different thanfalse
or totally empty. The current ternary condition logic is inverted. Main issue report here #543 .Also, it solves the conflict of the Laravel throttle middleware cutting the flow to Fortify throttle's own handlers by adding more granular control over the rate limits for Fortify, Laravel middleware, and the decay in seconds.
Finally, this solution will keep both throttle protections of Fortify's own handler and Laravel default middleware. If the configs proposed here are followed, the Fortify
EnsureLoginIsNotThrottled
will be triggered first returning a friendly messageToo many requests. Please try again in X seconds.
which plays nicely with InertiaJS (Other issue #312) and if the requests continue replicating a brute force behaviour, then Laravel kicks in.In the current setup, there is a lack of clarity and differentiation between Laravel middleware throttle and Fortify's own throttle handler considering one limiter config only. Also, it has been demonstrated through multiple issues reported that there is a problem with overlapping and conflicting two approaches.
Steps to reproduce without this fix
config/fortify.php
as follows:Route::post(RoutePath::for('login', '/login')
keeping everything else as is, see below: (Fortify has its own throttle error handlers, it shouldn't need to rely on Laravel defaults throttle middleware)AuthenticatedSessionController
in Fortify changing the line for theEnsureLoginIsNotThrottled
below toconfig('fortify.limiters.login') ? EnsureLoginIsNotThrottled::class : null
. Just invert it.fortify/src/Http/Controllers/AuthenticatedSessionController.php
Lines 85 to 87 in a725684
Relevant issues found
AuthenticatedSessionController
seems incorrect #543