Skip to content

Commit

Permalink
Improve rate limiting (mastodon#10860)
Browse files Browse the repository at this point in the history
* Rate limit based on remote address IP, not on potential reverse proxy

* Limit rate of unauthenticated API requests further

* Rate-limit paging requests to one every 3 seconds
  • Loading branch information
ClearlyClaire authored and multiple creatures committed Nov 19, 2019
1 parent b08d294 commit c068f90
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def paging_request?
end

throttle('throttle_unauthenticated_api', limit: 300, period: 5.minutes) do |req|
req.remote_ip if req.api_request? && req.unauthenticated?
req.remote_ip if req.api_request? && !req.authenticated?
end

throttle('throttle_api_media', limit: 300, period: 5.minutes) do |req|
Expand All @@ -70,7 +70,7 @@ def paging_request?
end

throttle('throttle_unauthenticated_media_proxy', limit: 30, period: 30.minutes) do |req|
req.remote_ip if req.unauthenticated? && req.path.start_with?('/media_proxy')
req.remote_ip if !req.authenticated? && req.path.start_with?('/media_proxy')
end

throttle('throttle_api_sign_up', limit: 5, period: 30.minutes) do |req|
Expand All @@ -83,7 +83,7 @@ def paging_request?
end

throttle('throttle_unauthenticated_paging', limit: 300, period: 15.minutes) do |req|
req.remote_ip if req.paging_request? && req.unauthenticated?
req.remote_ip if req.paging_request? && !req.authenticated?
end

API_DELETE_REBLOG_REGEX = /\A\/api\/v1\/statuses\/[\d]+\/unreblog/.freeze
Expand Down

0 comments on commit c068f90

Please sign in to comment.