mirror of
https://github.com/discourse/discourse.git
synced 2024-12-14 01:15:58 +08:00
FEATURE: Add global rate limit for anon searches (#10208)
This commit is contained in:
parent
3f7658cc6e
commit
6aad9cd0c8
|
@ -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
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user