feat: Allow support for trusted IPs to disable throttling (#11226)

Co-authored-by: Pranav <pranav@chatwoot.com>
This commit is contained in:
ElvioRibeiro
2025-05-08 20:10:30 -03:00
committed by GitHub
parent 823c3df27f
commit c73f8aefc5
2 changed files with 17 additions and 4 deletions

View File

@@ -21,8 +21,9 @@ class Rack::Attack
end
def allowed_ip?
allowed_ips = ['127.0.0.1', '::1']
allowed_ips.include?(remote_ip)
default_allowed_ips = ['127.0.0.1', '::1']
env_allowed_ips = ENV.fetch('RACK_ATTACK_ALLOWED_IPS', '').split(',').map(&:strip)
(default_allowed_ips + env_allowed_ips).include?(remote_ip)
end
# Rails would allow requests to paths with extentions, so lets compare against the path with extention stripped
@@ -32,6 +33,17 @@ class Rack::Attack
end
end
### Safelist IPs from Environment Variable ###
#
# This block ensures requests from any IP present in RACK_ATTACK_ALLOWED_IPS
# will bypass Rack::Attacks throttling rules.
#
# Example: RACK_ATTACK_ALLOWED_IPS="127.0.0.1,::1,192.168.0.10"
Rack::Attack.safelist('trusted IPs') do |req|
req.allowed_ip?
end
### Throttle Spammy Clients ###
# If any single client IP is making tons of requests, then they're