From 635d13a8b7eb17f65462ea44c9911755a45ab8c7 Mon Sep 17 00:00:00 2001 From: nahi Date: Fri, 24 Jun 2011 11:05:59 +0000 Subject: * lib/webrick/httprequest.rb (setup_forwarded_info): Parsing request header failed when the request is from 2 or more Apache reverse proxies. It's said that all X-Forwarded-* headers will contain more than one (comma-separated) value if the original request already contained one of these headers. Since we could use these values as Host header, we choose the initial(first) value. See #4922. * test/webrick/test_httprequest.rb (test_forwarded): Test it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32222 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/webrick/httprequest.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/webrick') diff --git a/lib/webrick/httprequest.rb b/lib/webrick/httprequest.rb index 5dda878e99..1e8789d2d6 100644 --- a/lib/webrick/httprequest.rb +++ b/lib/webrick/httprequest.rb @@ -434,10 +434,18 @@ module WEBrick ^(::ffff:)?(10|172\.(1[6-9]|2[0-9]|3[01])|192\.168)\. /ixo + # It's said that all X-Forwarded-* headers will contain more than one + # (comma-separated) value if the original request already contained one of + # these headers. Since we could use these values as Host header, we choose + # the initial(first) value. (apr_table_mergen() adds new value after the + # existing value with ", " prefix) def setup_forwarded_info - @forwarded_server = self["x-forwarded-server"] + if @forwarded_server = self["x-forwarded-server"] + @forwarded_server = @forwarded_server.split(",", 2).first + end @forwarded_proto = self["x-forwarded-proto"] if host_port = self["x-forwarded-host"] + host_port = host_port.split(",", 2).first @forwarded_host, tmp = host_port.split(":", 2) @forwarded_port = (tmp || (@forwarded_proto == "https" ? 443 : 80)).to_i end -- cgit v1.2.3