LoginSignup
2
1

More than 5 years have passed since last update.

Rack::Attack.throttle の設定でハマった

Last updated at Posted at 2018-06-14

Rack::AttackはRackで動いてるウェブアプリを攻撃から守るgem。throttle の設定書いてる時にハマったのでメモ。

何が起きたか

環境変数に設定書いとくかーと思ったら数値で書くべき設定 limitperiod の型が文字列になってたので例外になってた。起動時は例外にならないので、実際のリクエストがそこで処理されるまで気づかない。具体的な箇所はlib/rack/attack/throttle.rb#L37 の count > current_countArgumentError (comparison of Integer with String failed) になる。

対策

.to_i とかする。

Rack::Attack.throttle("requests by ip", limit: ENV['LIMIT'].to_i, period: ENV['PERIOD'].to_i) do |request|
  request.ip
end
.env
LIMIT=6
PERIOD=60
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1