-
Notifications
You must be signed in to change notification settings - Fork 337
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
Potential Bug in Rack-Attack Gem with Ruby on Rails #668
Comments
Hi @dadiaz18, is it possible that this report is related to #578 ? That the throttling/blocking happens in time windows of the specified duration but that not necessarily blocks one requester for the exact specified time? related code rack-attack/lib/rack/attack/cache.rb Lines 69 to 74 in 427fdfa
|
The truth is that I didn’t analyze the behavior of that function, but it could be closely related. All I did was run tests on a code implemented with the example above and measured the TTL times of Redis that were assigned to track behaviors starting from the first action. I concluded that the problem wasn’t Redis or the versions I had installed; it was a custom implementation of Rack::Attack that I didn’t examine closely. |
Ok, makes sense. I was also confused the first time I used I'll close this issue, given that it's how it has been working since the creation of the gem. That said, I'm open to change its behavior, but it should be done under a non-default configuration since it'd change a core aspect of the gem. |
I get that the current approach just does not cut it for me. Thank you! |
Gem Versions:
Context
I encountered an issue with the rack-attack gem when applied to a Rails application. I noticed that the TTL (Time-to-Live) values for Redis keys are inconsistently applied, causing problems with request rate limiting.
Problem Description
When blocking requests based on actions taken on an endpoint, the filters apply a TTL in Redis that does not align with the expected duration. This inconsistency happens randomly. For instance, if a 3-minute window is supposed to validate more than 20 hits, the Redis key should have a TTL of approximately 180 seconds. However, in some cases, it only applies a TTL of 80 seconds, making it impossible to validate the conditions because the data persists incorrectly.
This issue is not noticeable with smaller numbers of hits in a shorter time frame (e.g., 10 hits in one minute) because the TTL mismatch is less obvious. For example, the expected TTL might be 60 seconds, but it sometimes applies 30 seconds, thus obscuring the error.
Example code for implementation
Logs of TTLs wrongly applied when I start the counters
Please, any possible solution related to this?
Thanks.
The text was updated successfully, but these errors were encountered: