Permalink
Browse files

Fixed AbstractRequest#remote_ip for users going through proxies - Patch

#228 [Eric Hodel]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@12 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 4370466 commit 18d614040a709918ce97b9ef49781b0db78ed0cd @dhh dhh committed Nov 25, 2004
Showing with 11 additions and 9 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +9 −9 actionpack/lib/action_controller/request.rb
@@ -1,5 +1,7 @@
*CVS*
+* Fixed AbstractRequest#remote_ip for users going through proxies - Patch #228 [Eric Hodel]
+
* Added Request#ssl? which is shorthand for @request.protocol == "https://"
* Added the choice to call form_tag with no arguments (resulting in a form posting to current action) [bitsweat]
@@ -33,17 +33,17 @@ def delete?
# delimited list in the case of multiple chained proxies; the first is
# the originating IP.
def remote_ip
- if env['HTTP_CLIENT_IP']
- env['HTTP_CLIENT_IP']
- elsif env['HTTP_X_FORWARDED_FOR']
- remote_ip = env['HTTP_X_FORWARDED_FOR'].split(',').reject { |ip|
+ return env['HTTP_CLIENT_IP'] if env.include? 'HTTP_CLIENT_IP'
+
+ if env.include? 'HTTP_X_FORWARDED_FOR' then
+ remote_ips = env['HTTP_X_FORWARDED_FOR'].split(',').reject do |ip|
ip =~ /^unknown$|^(10|172\.16|192\.168)\./i
- }.first
-
- remote_ip ? remote_ip.strip : env['REMOTE_ADDR']
- else
- env['REMOTE_ADDR']
+ end
+
+ return remote_ips.first.strip unless remote_ips.empty?
end
+
+ return env['REMOTE_ADDR']
end
def request_uri

0 comments on commit 18d6140

Please sign in to comment.