-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[5.5] Request throttling #19807
[5.5] Request throttling #19807
Conversation
|
||
$maxAttempts = explode('|', $maxAttempts, 2); | ||
|
||
return $maxAttempts[(int) $request->user()]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be $maxAttempts[$request->user() ? 1 : 0]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was using it the other way around. Thx
I don't want this skipNotModified option. It makes the actual attaching of the middleware unintelligible. |
Hi, I have seen in Regards |
Just want to chime in here as well. With this PR the throttle middleware no longer takes into account the request's route. So if you wanted to throttle more than 1 route you can no longer do this, regardless of whether the user is authenticated or not. Is this really the desired default behavior? If you set up a throttle middleware on two different routes, their counts overlap? |
There is no perfect solution for this but it seems to adapt to the most frequent cases. I personally never use this middleware as it, and always extend it as I need to separate hits in different "buckets" (API and search). I encourage you to do the same. |
More discussion here: #22929 |
I'm currently extending it for this reason. Personally I think the best default would be:
Unfortunately, I don't see an easy way to do this, apart from extending the base middleware and creating two separate throttle middleware for each purpose. So, I can see the reason to default to what you've done. Most people probably use this to rate limit their entire API. What should probably happen is the docs should be updated to reflect that this middleware is meant to be applied to a single route group. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I guess
At the moment, the request throttling system allows to limit the number of request per route and IP.
This is not adapted to the following cases:
Unauthenticated mode
In this case this system would be very quickly inefficient to handle a dDOS, and a service like https://www.cloudflare.com would be a much more adapted and reliable solution.
Still we want to be able to provide this feature for guest users.
Authenticated mode
We want to identify the user by his ID, not his IP.
Authenticated mode with a different quota
We want to provide a different rate limit for authenticated user.
Per group (of routes) throttling
The throttling cannot handle a group of route as at the moment, the throttling that the route itself in consideration.
Conditional requests
In many services, to encourage users to use HTTP caching mechanism, an thus avoid workload on the server, the
304
responses don't count for a hit.Content type compliant response
We might want to return a
429
response if the user has made too many attempts. We might also want to choose the content-type for this response (likeapplication/json
for an API response).In this case, it seems better to throw an exception instead of returning a response. The exception can be later tweaked in the application Exception handler, if necessary.
TODO:
Usage