From 3fcf9cf6f9685c419b2cfdb9a3d5f443cb7b692c Mon Sep 17 00:00:00 2001 From: Santiago Bartesaghi Date: Mon, 16 Oct 2023 18:08:59 -0300 Subject: [PATCH] Fix Rails 4 suite --- lib/rack/attack/configuration.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/rack/attack/configuration.rb b/lib/rack/attack/configuration.rb index ba2715e1..a4bdc987 100644 --- a/lib/rack/attack/configuration.rb +++ b/lib/rack/attack/configuration.rb @@ -61,11 +61,15 @@ def blocklist(name = nil, &block) end def blocklist_ip(ip_address) - @anonymous_blocklists << Blocklist.new { |request| IPAddr.new(ip_address).include?(IPAddr.new(*request.ip)) } + @anonymous_blocklists << Blocklist.new do |request| + request.ip && !request.ip.empty? && IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) + end end def safelist_ip(ip_address) - @anonymous_safelists << Safelist.new { |request| IPAddr.new(ip_address).include?(IPAddr.new(*request.ip)) } + @anonymous_safelists << Safelist.new do |request| + request.ip && !request.ip.empty? && IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) + end end def throttle(name, options, &block)