Skip to content

Commit

Permalink
Apply a 25x rate limit by IP even to authenticated requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron committed Dec 9, 2017
1 parent a72d03f commit 4de2095
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/controllers/concerns/rate_limit_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def rate_limit_reset
end

def api_throttle_data
request.env['rack.attack.throttle_data']['throttle_authenticated_api'] ||
request.env['rack.attack.throttle_data']['throttle_unauthenticated_api']
most_limited_type, = request.env['rack.attack.throttle_data'].min_by { |_, v| v[:limit] }
request.env['rack.attack.throttle_data'][most_limited_type]
end

def request_time
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def web_request?
req.api_request? && req.authenticated_user_id
end

throttle('throttle_unauthenticated_api', limit: 300, period: 5.minutes) do |req|
req.ip if req.api_request? && req.unauthenticated?
throttle('throttle_unauthenticated_api', limit: 7_500, period: 5.minutes) do |req|
req.ip if req.api_request?
end

throttle('protected_paths', limit: 5, period: 5.minutes) do |req|
Expand Down

0 comments on commit 4de2095

Please sign in to comment.