FEATURE: Add global rate limit for anon searches (#10208)

This commit is contained in:
Rafael dos Santos Silva 2020-07-09 20:08:34 -03:00 committed by Jeff Wong
parent 3f7658cc6e
commit 6aad9cd0c8
3 changed files with 7 additions and 3 deletions

View File

@ -159,7 +159,8 @@ class SearchController < ApplicationController
if current_user.present? if current_user.present?
RateLimiter.new(current_user, "search-min", SiteSetting.rate_limit_search_user, 1.minute).performed! RateLimiter.new(current_user, "search-min", SiteSetting.rate_limit_search_user, 1.minute).performed!
else else
RateLimiter.new(nil, "search-min-#{request.remote_ip}", SiteSetting.rate_limit_search_anon, 1.minute).performed! RateLimiter.new(nil, "search-min-#{request.remote_ip}", SiteSetting.rate_limit_search_anon_user, 1.minute).performed!
RateLimiter.new(nil, "search-min-anon-global", SiteSetting.rate_limit_search_anon_global, 1.minute).performed!
end end
rescue RateLimiter::LimitExceeded => e rescue RateLimiter::LimitExceeded => e
return e return e

View File

@ -1542,7 +1542,10 @@ rate_limits:
rate_limit_create_post: 5 rate_limit_create_post: 5
rate_limit_new_user_create_topic: 120 rate_limit_new_user_create_topic: 120
rate_limit_new_user_create_post: 30 rate_limit_new_user_create_post: 30
rate_limit_search_anon: rate_limit_search_anon_global:
hidden: true
default: 150
rate_limit_search_anon_user:
hidden: true hidden: true
default: 15 default: 15
rate_limit_search_user: rate_limit_search_user:

View File

@ -183,7 +183,7 @@ describe SearchController do
context 'rate limited' do context 'rate limited' do
before do before do
SiteSetting.rate_limit_search_user = 3 SiteSetting.rate_limit_search_user = 3
SiteSetting.rate_limit_search_anon = 2 SiteSetting.rate_limit_search_anon_user = 2
end end
it 'rate limits searches' do it 'rate limits searches' do