You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to first throttle abusers but then if they continue issue a ban, I am not being successful as everything is getting "forbidden"
classRack::Attack##LETS GIVE A FIRST THROTTLEthrottle('req/ip',:limit=>50,:period=>1.minutes)do |req|
req.ipend##IF IT CONTINUES BAN FOR 24HRack::Attack.blocklist('fail2ban pentesters')do |req|
Rack::Attack::Fail2Ban.filter("pentesters-#{req.ip}",:maxretry=>100,:findtime=>5.minutes,:bantime=>1.days)dotrue## I want to consider all requests, including legitsendendend
in your fail2ban.filter code, check for the throttle key in Rails.cache.read("rack::attack:#{Time.now.to_i / 1.minute}:req/ip:127.0.0.1") - if the count is over a certain amount return true and it'll ban.
Solved with using throttled?(req) in Rack::Attack::Fail2Ban.filter with maxretry: 0
Rack::Attack.throttle('xhr/ip', limit: 10, period: 1.minute) do |req|
req.path.include?('/api/')
end
Rack::Attack.blocklist('fail2ban') do |req|
Rack::Attack::Fail2Ban.filter("xhr/#{req.ip}", maxretry: 0, findtime: 1.minute, bantime: 1.day) do
throttled?(req) # Counts repeatedly
end
end
@kruglyjmax using throttled? seems to doubly increment the throttle (ie. the counter in redis is updated both by the throttle and by the fail2ban). Have you gotten around this?
Activity
acegilz commentedon Jan 10, 2017
up..
courtenay commentedon Mar 26, 2017
in your fail2ban.filter code, check for the throttle key in
Rails.cache.read("rack::attack:#{Time.now.to_i / 1.minute}:req/ip:127.0.0.1")- if the count is over a certain amount return true and it'll ban.feliperaul commentedon Jan 16, 2018
@courtenay I like your suggestion, but in this case we should set maxretry to 0 in the Fail2Ban filter, right?
kruglyjmax commentedon Apr 19, 2020
Solved with using
throttled?(req)inRack::Attack::Fail2Ban.filterwithmaxretry: 0dvandersluis commentedon Feb 26, 2021
@kruglyjmax using
throttled?seems to doubly increment the throttle (ie. the counter in redis is updated both by the throttle and by the fail2ban). Have you gotten around this?dvandersluis commentedon Feb 26, 2021
I solved my issue by adding a method to
Rack::Attack::Throttle:And then I can use: