add Gem rack_attack for prevent attack brute-force

This commit is contained in:
pedong 2019-07-03 15:22:31 +02:00 committed by simon lehericey
parent cab5b5cd9b
commit fc8cebd78d
4 changed files with 26 additions and 0 deletions

View file

@ -0,0 +1,21 @@
if ENV['RAILS_ENV'] != 'test'
class Rack::Attack
throttle('logins/ip', limit: 5, period: 20.seconds) do |req|
if req.path == '/users/sign_in' && req.post?
req.ip
end
end
throttle('stats/ip', limit: 5, period: 20.seconds) do |req|
if req.path == '/stats'
req.ip
end
end
throttle('contact/ip', limit: 5, period: 20.seconds) do |req|
if req.path == '/contact' && req.post?
req.ip
end
end
end
end