diff options
author | Starfall <us@starfall.systems> | 2020-07-07 10:08:13 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2020-07-07 10:10:33 -0500 |
commit | 147b4e7713cf5555fc4b515c7d88da49bf597f46 (patch) | |
tree | 67e33c2838eea691088e77ec4e19afb23104e77d /config/initializers/rack_attack.rb | |
parent | cfd52a032aa4ee545d479b65a295e6a9e77c4f4f (diff) | |
parent | c4e1b82caf5c932a3c19bc77726c9e3ab3d2c46a (diff) |
Mastodon 3.1.5 / Merge branch 'glitch' into main
Diffstat (limited to 'config/initializers/rack_attack.rb')
-rw-r--r-- | config/initializers/rack_attack.rb | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index 09458c540..cd29afac5 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -38,15 +38,6 @@ class Rack::Attack end end - PROTECTED_PATHS = %w( - /auth/sign_in - /auth - /auth/password - /auth/confirmation - ).freeze - - PROTECTED_PATHS_REGEX = Regexp.union(PROTECTED_PATHS.map { |path| /\A#{Regexp.escape(path)}/ }) - Rack::Attack.safelist('allow from localhost') do |req| req.remote_ip == '127.0.0.1' || req.remote_ip == '::1' end @@ -86,8 +77,32 @@ class Rack::Attack req.authenticated_user_id if (req.post? && req.path =~ API_DELETE_REBLOG_REGEX) || (req.delete? && req.path =~ API_DELETE_STATUS_REGEX) end - throttle('protected_paths', limit: 25, period: 5.minutes) do |req| - req.remote_ip if req.post? && req.path =~ PROTECTED_PATHS_REGEX + throttle('throttle_sign_up_attempts/ip', limit: 25, period: 5.minutes) do |req| + req.remote_ip if req.post? && req.path == '/auth' + end + + throttle('throttle_password_resets/ip', limit: 25, period: 5.minutes) do |req| + req.remote_ip if req.post? && req.path == '/auth/password' + end + + throttle('throttle_password_resets/email', limit: 5, period: 30.minutes) do |req| + req.params.dig('user', 'email').presence if req.post? && req.path == '/auth/password' + end + + throttle('throttle_email_confirmations/ip', limit: 25, period: 5.minutes) do |req| + req.remote_ip if req.post? && req.path == '/auth/confirmation' + end + + throttle('throttle_email_confirmations/email', limit: 5, period: 30.minutes) do |req| + req.params.dig('user', 'email').presence if req.post? && req.path == '/auth/password' + end + + throttle('throttle_login_attempts/ip', limit: 25, period: 5.minutes) do |req| + req.remote_ip if req.post? && req.path == '/auth/sign_in' + end + + throttle('throttle_login_attempts/email', limit: 25, period: 1.hour) do |req| + req.session[:attempt_user_id] || req.params.dig('user', 'email').presence if req.post? && req.path == '/auth/sign_in' end self.throttled_response = lambda do |env| |