Skip to content
Browse files

Merge pull request #4202 from dasch/request-remote-ip

Fix bug in `ActionController::Request#remote_ip`
  • Loading branch information...
2 parents e0774e4 + cd2136a commit 2eb197e72f8ea9a91399cd22a57b1d18774a23e4 @tenderlove tenderlove committed Dec 29, 2011
Showing with 4 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_controller/request.rb
  2. +3 −0 actionpack/test/controller/request_test.rb
View
2 actionpack/lib/action_controller/request.rb
@@ -225,7 +225,7 @@ def remote_ip
not_trusted_addrs = remote_addr_list.reject {|addr| addr =~ TRUSTED_PROXIES}
return not_trusted_addrs.first unless not_trusted_addrs.empty?
end
- remote_ips = @env['HTTP_X_FORWARDED_FOR'] && @env['HTTP_X_FORWARDED_FOR'].split(',')
+ remote_ips = @env['HTTP_X_FORWARDED_FOR'].present? && @env['HTTP_X_FORWARDED_FOR'].split(',')
if @env.include? 'HTTP_CLIENT_IP'
if ActionController::Base.ip_spoofing_check && remote_ips && !remote_ips.include?(@env['HTTP_CLIENT_IP'])
View
3 actionpack/test/controller/request_test.rb
@@ -20,6 +20,9 @@ def test_remote_ip
'HTTP_X_FORWARDED_FOR' => '3.4.5.6'
assert_equal '1.2.3.4', request.remote_ip
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => ''
+ assert_nil request.remote_ip
+
request = stub_request 'REMOTE_ADDR' => '127.0.0.1',
'HTTP_X_FORWARDED_FOR' => '3.4.5.6'
assert_equal '3.4.5.6', request.remote_ip

0 comments on commit 2eb197e

Please sign in to comment.
Something went wrong with that request. Please try again.