mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
reorder logic to not repeatedly extend ban after more failed requests
This commit is contained in:
parent
3f1c98a868
commit
94a304b815
1 changed files with 7 additions and 6 deletions
|
|
@ -6,14 +6,15 @@ module Rack
|
|||
bantime = options[:bantime] or raise ArgumentError, "Must pass bantime option"
|
||||
findtime = options[:findtime] or raise ArgumentError, "Must pass findtime option"
|
||||
maxretry = options[:maxretry] or raise ArgumentError, "Must pass maxretry option"
|
||||
|
||||
if yield
|
||||
|
||||
if banned?(discriminator)
|
||||
# Return true for blacklist
|
||||
true
|
||||
elsif yield
|
||||
fail!(name, discriminator, bantime, findtime, maxretry)
|
||||
else
|
||||
banned?(discriminator)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def fail!(name, discriminator, bantime, findtime, maxretry)
|
||||
count = cache.count("#{name}:#{discriminator}", findtime)
|
||||
|
|
@ -24,7 +25,7 @@ module Rack
|
|||
# Return true for blacklist
|
||||
true
|
||||
end
|
||||
|
||||
|
||||
def ban!(discriminator, bantime)
|
||||
cache.write("fail2ban:#{discriminator}", 1, bantime)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue