Skip to content

Commit bfac1ad

Browse files
author
normal
committed
webrick: filter out HTTP_PROXY for CGIHandler
* lib/webrick/httpservlet/cgihandler.rb (do_GET): delete HTTP_PROXY * test/webrick/test_cgi.rb (test_cgi_env): new test * test/webrick/webrick.cgi (do_GET): new endpoint to dump env [ruby-core:76511] [Bug #12610] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 39d0217 commit bfac1ad

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

lib/webrick/httpservlet/cgihandler.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def do_GET(req, res)
5252
meta = req.meta_vars
5353
meta["SCRIPT_FILENAME"] = @script_filename
5454
meta["PATH"] = @config[:CGIPathEnv]
55+
meta.delete("HTTP_PROXY")
5556
if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
5657
meta["SystemRoot"] = ENV["SystemRoot"]
5758
end

test/webrick/test_cgi.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ def test_bad_request
114114
}
115115
end
116116

117+
def test_cgi_env
118+
start_cgi_server do |server, addr, port, log|
119+
http = Net::HTTP.new(addr, port)
120+
req = Net::HTTP::Get.new("/webrick.cgi/dumpenv")
121+
req['proxy'] = 'http://example.com/'
122+
req['hello'] = 'world'
123+
http.request(req) do |res|
124+
env = Marshal.load(res.body)
125+
assert_equal 'world', env['HTTP_HELLO']
126+
assert_not_operator env, :include?, 'HTTP_PROXY'
127+
end
128+
end
129+
end
130+
117131
CtrlSeq = [0x7f, *(1..31)].pack("C*").gsub(/\s+/, '')
118132
CtrlPat = /#{Regexp.quote(CtrlSeq)}/o
119133
DumpPat = /#{Regexp.quote(CtrlSeq.dump[1...-1])}/o

test/webrick/webrick.cgi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ require "webrick/cgi"
44
class TestApp < WEBrick::CGI
55
def do_GET(req, res)
66
res["content-type"] = "text/plain"
7-
if (p = req.path_info) && p.length > 0
7+
if req.path_info == "/dumpenv"
8+
res.body = Marshal.dump(ENV.to_hash)
9+
elsif (p = req.path_info) && p.length > 0
810
res.body = p
911
elsif (q = req.query).size > 0
1012
res.body = q.keys.sort.collect{|key|

0 commit comments

Comments
 (0)