mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 12:53:42 +08:00
FEATURE: Shorten setting name to max_reqs
So it is consistent with other settings
This commit is contained in:
parent
83a346cd68
commit
f26ff290c3
|
@ -176,10 +176,10 @@ max_user_api_reqs_per_day = 2880
|
||||||
|
|
||||||
max_admin_api_reqs_per_key_per_minute = 60
|
max_admin_api_reqs_per_key_per_minute = 60
|
||||||
|
|
||||||
max_requests_per_ip_per_minute = 200
|
max_reqs_per_ip_per_minute = 200
|
||||||
max_requests_per_ip_per_10_seconds = 50
|
max_reqs_per_ip_per_10_seconds = 50
|
||||||
# global rate limiter will simply warn if the limit is exceeded, can be warn+block, warn, block or none
|
# global rate limiter will simply warn if the limit is exceeded, can be warn+block, warn, block or none
|
||||||
max_requests_per_ip_mode = none
|
max_reqs_per_ip_mode = none
|
||||||
|
|
||||||
# bypass rate limiting any IP resolved as a private IP
|
# bypass rate limiting any IP resolved as a private IP
|
||||||
max_requests_rate_limit_on_private = false
|
max_reqs_rate_limit_on_private = false
|
||||||
|
|
|
@ -156,21 +156,21 @@ class Middleware::RequestTracker
|
||||||
def rate_limit(env)
|
def rate_limit(env)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
GlobalSetting.max_requests_per_ip_mode == "block" ||
|
GlobalSetting.max_reqs_per_ip_mode == "block" ||
|
||||||
GlobalSetting.max_requests_per_ip_mode == "warn" ||
|
GlobalSetting.max_reqs_per_ip_mode == "warn" ||
|
||||||
GlobalSetting.max_requests_per_ip_mode == "warn+block"
|
GlobalSetting.max_reqs_per_ip_mode == "warn+block"
|
||||||
)
|
)
|
||||||
|
|
||||||
ip = Rack::Request.new(env).ip
|
ip = Rack::Request.new(env).ip
|
||||||
|
|
||||||
if !GlobalSetting.max_requests_rate_limit_on_private
|
if !GlobalSetting.max_reqs_rate_limit_on_private
|
||||||
return false if is_private_ip?(ip)
|
return false if is_private_ip?(ip)
|
||||||
end
|
end
|
||||||
|
|
||||||
limiter10 = RateLimiter.new(
|
limiter10 = RateLimiter.new(
|
||||||
nil,
|
nil,
|
||||||
"global_ip_limit_10_#{ip}",
|
"global_ip_limit_10_#{ip}",
|
||||||
GlobalSetting.max_requests_per_ip_per_10_seconds,
|
GlobalSetting.max_reqs_per_ip_per_10_seconds,
|
||||||
10,
|
10,
|
||||||
global: true
|
global: true
|
||||||
)
|
)
|
||||||
|
@ -178,7 +178,7 @@ class Middleware::RequestTracker
|
||||||
limiter60 = RateLimiter.new(
|
limiter60 = RateLimiter.new(
|
||||||
nil,
|
nil,
|
||||||
"global_ip_limit_60_#{ip}",
|
"global_ip_limit_60_#{ip}",
|
||||||
GlobalSetting.max_requests_per_ip_per_10_seconds,
|
GlobalSetting.max_reqs_per_ip_per_10_seconds,
|
||||||
10,
|
10,
|
||||||
global: true
|
global: true
|
||||||
)
|
)
|
||||||
|
@ -190,11 +190,11 @@ class Middleware::RequestTracker
|
||||||
limiter60.performed!
|
limiter60.performed!
|
||||||
rescue RateLimiter::LimitExceeded
|
rescue RateLimiter::LimitExceeded
|
||||||
if (
|
if (
|
||||||
GlobalSetting.max_requests_per_ip_mode == "warn" ||
|
GlobalSetting.max_reqs_per_ip_mode == "warn" ||
|
||||||
GlobalSetting.max_requests_per_ip_mode == "warn+block"
|
GlobalSetting.max_reqs_per_ip_mode == "warn+block"
|
||||||
)
|
)
|
||||||
Rails.logger.warn("Global IP rate limit exceeded for #{ip}: #{type} second rate limit, uri: #{env["REQUEST_URI"]}")
|
Rails.logger.warn("Global IP rate limit exceeded for #{ip}: #{type} second rate limit, uri: #{env["REQUEST_URI"]}")
|
||||||
!(GlobalSetting.max_requests_per_ip_mode == "warn")
|
!(GlobalSetting.max_reqs_per_ip_mode == "warn")
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -105,7 +105,7 @@ describe Middleware::RequestTracker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does nothing by default" do
|
it "does nothing by default" do
|
||||||
global_setting :max_requests_per_ip_per_10_seconds, 1
|
global_setting :max_reqs_per_ip_per_10_seconds, 1
|
||||||
|
|
||||||
status, _ = middleware.call(env)
|
status, _ = middleware.call(env)
|
||||||
status, _ = middleware.call(env)
|
status, _ = middleware.call(env)
|
||||||
|
@ -114,9 +114,9 @@ describe Middleware::RequestTracker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "blocks private IPs if not skipped" do
|
it "blocks private IPs if not skipped" do
|
||||||
global_setting :max_requests_per_ip_per_10_seconds, 1
|
global_setting :max_reqs_per_ip_per_10_seconds, 1
|
||||||
global_setting :max_requests_per_ip_mode, 'warn+block'
|
global_setting :max_reqs_per_ip_mode, 'warn+block'
|
||||||
global_setting :max_requests_rate_limit_on_private, true
|
global_setting :max_reqs_rate_limit_on_private, true
|
||||||
|
|
||||||
env1 = env("REMOTE_ADDR" => "127.0.0.2")
|
env1 = env("REMOTE_ADDR" => "127.0.0.2")
|
||||||
|
|
||||||
|
@ -128,9 +128,9 @@ describe Middleware::RequestTracker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does nothing for private IPs if skipped" do
|
it "does nothing for private IPs if skipped" do
|
||||||
global_setting :max_requests_per_ip_per_10_seconds, 1
|
global_setting :max_reqs_per_ip_per_10_seconds, 1
|
||||||
global_setting :max_requests_per_ip_mode, 'warn+block'
|
global_setting :max_reqs_per_ip_mode, 'warn+block'
|
||||||
global_setting :max_requests_rate_limit_on_private, false
|
global_setting :max_reqs_rate_limit_on_private, false
|
||||||
|
|
||||||
env1 = env("REMOTE_ADDR" => "127.0.3.1")
|
env1 = env("REMOTE_ADDR" => "127.0.3.1")
|
||||||
|
|
||||||
|
@ -142,8 +142,8 @@ describe Middleware::RequestTracker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does warn if rate limiter is enabled via warn+block" do
|
it "does warn if rate limiter is enabled via warn+block" do
|
||||||
global_setting :max_requests_per_ip_per_10_seconds, 1
|
global_setting :max_reqs_per_ip_per_10_seconds, 1
|
||||||
global_setting :max_requests_per_ip_mode, 'warn+block'
|
global_setting :max_reqs_per_ip_mode, 'warn+block'
|
||||||
|
|
||||||
status, _ = middleware.call(env)
|
status, _ = middleware.call(env)
|
||||||
status, _ = middleware.call(env)
|
status, _ = middleware.call(env)
|
||||||
|
@ -153,8 +153,8 @@ describe Middleware::RequestTracker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does warn if rate limiter is enabled" do
|
it "does warn if rate limiter is enabled" do
|
||||||
global_setting :max_requests_per_ip_per_10_seconds, 1
|
global_setting :max_reqs_per_ip_per_10_seconds, 1
|
||||||
global_setting :max_requests_per_ip_mode, 'warn'
|
global_setting :max_reqs_per_ip_mode, 'warn'
|
||||||
|
|
||||||
status, _ = middleware.call(env)
|
status, _ = middleware.call(env)
|
||||||
status, _ = middleware.call(env)
|
status, _ = middleware.call(env)
|
||||||
|
@ -164,8 +164,8 @@ describe Middleware::RequestTracker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does block if rate limiter is enabled" do
|
it "does block if rate limiter is enabled" do
|
||||||
global_setting :max_requests_per_ip_per_10_seconds, 1
|
global_setting :max_reqs_per_ip_per_10_seconds, 1
|
||||||
global_setting :max_requests_per_ip_mode, 'block'
|
global_setting :max_reqs_per_ip_mode, 'block'
|
||||||
|
|
||||||
env1 = env("REMOTE_ADDR" => "1.1.1.1")
|
env1 = env("REMOTE_ADDR" => "1.1.1.1")
|
||||||
env2 = env("REMOTE_ADDR" => "1.1.1.2")
|
env2 = env("REMOTE_ADDR" => "1.1.1.2")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user