我正在我的 rails 应用程序中实现 Kickstarter 的 Rack-attack。
白名单/黑名单过滤工作正常,但我在使用 Allow2Ban 锁定影响我的登录(设计)页面的 IP 地址时遇到问题。注意:我在本地对此进行了测试,并已将 localhost 从白名单中删除。
# Lockout IP addresses that are hammering your login page.
# After 3 requests in 1 minute, block all requests from that IP for 1 hour.
Rack::Attack.blacklist('allow2ban login scrapers') do |req|
# `filter` returns false value if request is to your login page (but still
# increments the count) so request below the limit are not blocked until
# they hit the limit. At that point, filter will return true and block.
Rack::Attack::Allow2Ban.filter(req.ip, :maxretry => 3, :findtime => 1.minute, :bantime => 1.hour) do
# The count for the IP is incremented if the return value is truthy.
req.path == '/sign_in' and req.post?
end
end
在 Rack-attack 文档中,它明确指出限制功能需要缓存,即:
Rack::Attack.throttle('req/ip', :limit => 5, :period => 1.second) do |req| )
,但它没有为 Allow2Ban 说明这一点。任何人都知道 Allow2Ban 是否需要缓存,或者我是否在 Devise 登录页面上使用上面的代码错误地实现了