configure rack attack to allow 5r/s for the load_url_title route

This commit is contained in:
Devin Howard 2016-09-25 23:00:07 +08:00
parent ceb2699760
commit 7f8110b6be
2 changed files with 17 additions and 0 deletions

View file

@ -26,6 +26,8 @@ module Metamaps
Doorkeeper::ApplicationController.helper ApplicationHelper
end
config.middleware.use Rack::Attack
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]

View file

@ -0,0 +1,15 @@
class Rack::Attack
end
Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new
# Throttle requests to 5 requests per second per ip
Rack::Attack.throttle('load_url_title/req/ip', :limit => 5, :period => 1.second) do |req|
# If the return value is truthy, the cache key for the return value
# is incremented and compared with the limit. In this case:
# "rack::attack:#{Time.now.to_i/1.second}:load_url_title/req/ip:#{req.ip}"
#
# If falsy, the cache key is neither incremented nor checked.
req.ip if req.path === 'hacks/load_url_title'
end