configure rack attack to allow 5r/s for the load_url_title route
This commit is contained in:
parent
ceb2699760
commit
7f8110b6be
2 changed files with 17 additions and 0 deletions
|
@ -26,6 +26,8 @@ module Metamaps
|
||||||
Doorkeeper::ApplicationController.helper ApplicationHelper
|
Doorkeeper::ApplicationController.helper ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
|
config.middleware.use Rack::Attack
|
||||||
|
|
||||||
# Configure sensitive parameters which will be filtered from the log file.
|
# Configure sensitive parameters which will be filtered from the log file.
|
||||||
config.filter_parameters += [:password]
|
config.filter_parameters += [:password]
|
||||||
|
|
||||||
|
|
15
config/initializers/rack-attack.rb
Normal file
15
config/initializers/rack-attack.rb
Normal 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
|
Loading…
Reference in a new issue