Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,12 @@ def connect
write_timeout: @write_timeout,
continue_timeout: @continue_timeout,
debug_output: @debug_output)
if /[\r\n]/.match?("#{conn_address}:#{@port}")
raise ArgumentError, "address and port cannot include CR/LF"
end
if /[\r\n]/.match?(@address)
raise ArgumentError, "address cannot include CR/LF"
end
buf = +"CONNECT #{conn_address}:#{@port} HTTP/#{HTTPVersion}\r\n" \
"Host: #{@address}:#{@port}\r\n"
if proxy_user
Expand Down
18 changes: 18 additions & 0 deletions test/net/http/test_https_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ def test_https_proxy_authentication
end


def test_https_proxy_rejects_crlf_in_address
TCPServer.open("127.0.0.1", 0) {|serv|
_, port, _, _ = serv.addr
client_thread = Thread.new {
proxy = Net::HTTP.Proxy("127.0.0.1", port)
http = proxy.new("foo.example.org\r\nX-Injected: 1\r\nbar.example.org", 8000)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
assert_raise(ArgumentError) { http.start }
}
server_thread = Thread.new {
sock = serv.accept
sock.close
}
assert_join_threads([client_thread, server_thread])
}
end

def read_fixture(key)
File.read(File.expand_path("../fixtures/#{key}", __dir__))
end
Expand Down
Loading