使用Rack :: Attack来限制Basic Auth

时间:2014-03-07 21:32:45

标签: basic-authentication throttling rack-middleware rackattack

我为我的应用设置了gem rack-attack。我想开始基于IP限制基本身份验证。

我的基本身份验证代码设置如下:

# config/environments/production.rb
config.middleware.insert_after(::Rack::Lock, '::Rack::Auth::Basic', ENV['RAILS_ENV') do |u, p|
  [u, p] == [ENV['BASIC_AUTH_USERNAME'], ENV['BASIC_AUTH_PASSWORD']]
end

我想我的机架攻击会包含这样的内容:

# config/initializers/rack_attack.rb
Rack::Attack.throttle('req/ip', limit: 2, period: 60.seconds) do |req| req.ip 
    # what should belong here???
end

1 个答案:

答案 0 :(得分:0)

有关此问题,请参阅我的github comment