Change rack attack example.
This commit is contained in:
parent
e328668f29
commit
52e903e99f
|
@ -8,11 +8,19 @@ paths_to_be_protected = [
|
|||
"#{Rails.application.config.relative_url_root}/api/#{API::API.version}/session.json",
|
||||
"#{Rails.application.config.relative_url_root}/api/#{API::API.version}/session",
|
||||
"#{Rails.application.config.relative_url_root}/users",
|
||||
"#{Rails.application.config.relative_url_root}/users/confirmation"
|
||||
"#{Rails.application.config.relative_url_root}/users/confirmation",
|
||||
"#{Rails.application.config.relative_url_root}/unsubscribes/*"
|
||||
|
||||
]
|
||||
|
||||
paths_to_be_protected.map! { |path| Regexp.new(path) }
|
||||
|
||||
unless Rails.env.test?
|
||||
Rack::Attack.throttle('protected paths', limit: 10, period: 60.seconds) do |req|
|
||||
req.ip if paths_to_be_protected.include?(req.path) && req.post?
|
||||
if req.post?
|
||||
paths_paths_to_be_protected.each do |protected_path|
|
||||
req.ip if req.path =~ protected_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue