Skip to content

Commit

Permalink
Merge pull request rails#4202 from dasch/request-remote-ip
Browse files Browse the repository at this point in the history
Fix bug in `ActionController::Request#remote_ip`
  • Loading branch information
tenderlove committed Dec 29, 2011
2 parents e0774e4 + cd2136a commit 2eb197e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/request.rb
Expand Up @@ -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'])
Expand Down
3 changes: 3 additions & 0 deletions actionpack/test/controller/request_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 2eb197e

Please sign in to comment.