]> cat aescling's git repositories - mastodon.git/commitdiff
Add rate limits for logins and sign-ups by IP (5 in 5 minutes) (#2079)
authorEugen <eugen@zeonfederated.com>
Tue, 18 Apr 2017 20:29:14 +0000 (22:29 +0200)
committerGitHub <noreply@github.com>
Tue, 18 Apr 2017 20:29:14 +0000 (22:29 +0200)
* Add rate limits for logins and sign-ups by IP (5 in 5 minutes)
Should be enough for normal attempts

* Add rate limit for forgotten password form as well

config/initializers/rack_attack.rb [moved from config/initializers/rack-attack.rb with 50% similarity]

similarity index 50%
rename from config/initializers/rack-attack.rb
rename to config/initializers/rack_attack.rb
index 70f7846d19eb48d72232c7580429fc617daf3906..67ec7c919aa4f58f8ee8bd5767ef8f1410f6179e 100644 (file)
@@ -1,7 +1,24 @@
+# frozen_string_literal: true
+
 class Rack::Attack
   # Rate limits for the API
   throttle('api', limit: 300, period: 5.minutes) do |req|
-    req.ip if req.path.match(/\A\/api\/v/)
+    req.ip if req.path =~ /\A\/api\/v/
+  end
+
+  # Rate limit logins
+  throttle('login', limit: 5, period: 5.minutes) do |req|
+    req.ip if req.path == '/auth/sign_in' && req.post?
+  end
+
+  # Rate limit sign-ups
+  throttle('register', limit: 5, period: 5.minutes) do |req|
+    req.ip if req.path == '/auth' && req.post?
+  end
+
+  # Rate limit forgotten passwords
+  throttle('reminder', limit: 5, period: 5.minutes) do |req|
+    req.ip if req.path == '/auth/password' && req.post?
   end
 
   self.throttled_response = lambda do |env|