Skip to content

Commit

Permalink
Fix #588 don't fail if request.ip is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
santib committed Oct 16, 2023
1 parent 9a7815c commit ceabba1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/rack/attack/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ 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 { |request| IPAddr.new(ip_address).include?(IPAddr.new(*request.ip)) }
end

def safelist_ip(ip_address)
@anonymous_safelists << Safelist.new { |request| IPAddr.new(ip_address).include?(IPAddr.new(request.ip)) }
@anonymous_safelists << Safelist.new { |request| IPAddr.new(ip_address).include?(IPAddr.new(*request.ip)) }
end

def throttle(name, options, &block)
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/blocking_ip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
end

it "succeeds if IP doesn't match" do
get "/", {}, "REMOTE_ADDR" => "5.6.7.8"
get "/", {}, "REMOTE_ADDR" => ""

assert_equal 200, last_response.status
end
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/safelisting_ip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

it "forbids request if blocklist condition is true and safelist is false" do
get "/admin", {}, "REMOTE_ADDR" => "1.2.3.4"
get "/admin", {}, "REMOTE_ADDR" => ""

assert_equal 403, last_response.status
end
Expand Down

0 comments on commit ceabba1

Please sign in to comment.