Skip to content

Commit 6592a81

Browse files
author
Kylo Ginsberg
committed
Merge pull request #4921 from underscorgan/merge-cve-to-stable
(maint) merge-back for work for CVE-2016-2785
2 parents 7f28f9f + 8d2ce79 commit 6592a81

File tree

6 files changed

+47
-17
lines changed

6 files changed

+47
-17
lines changed

lib/puppet/indirector/catalog/compiler.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ def compile(node, options)
254254
raise Puppet::Error, "Unable to find a common checksum type between agent '#{options[:checksum_type]}' and master '#{known_checksum_types}'." unless checksum_type
255255
end
256256

257-
str = "Compiled %s for #{node.name}" % [checksum_type ? 'static catalog' : 'catalog']
257+
str = "Compiled %s for " % [checksum_type ? 'static catalog' : 'catalog']
258+
str += node.name
258259
str += " in environment #{node.environment}" if node.environment
259260
config = nil
260261

lib/puppet/network/http/api/indirected_routes.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ def uri2indirection(http_method, uri, params)
104104
raise ArgumentError, "No request key specified in #{uri}"
105105
end
106106

107-
key = URI.unescape(key)
108-
109107
[indirection, method, key, params]
110108
end
111109

lib/puppet/network/http/rack/rest.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'cgi'
33
require 'puppet/network/http/handler'
44
require 'puppet/util/ssl'
5+
require 'uri'
56

67
class Puppet::Network::HTTP::RackREST
78
include Puppet::Network::HTTP::Handler
@@ -79,7 +80,15 @@ def params(request)
7980

8081
# what path was requested? (this is, without any query parameters)
8182
def path(request)
82-
request.path
83+
# The value that Passenger provides for 'path' is escaped
84+
# (URL percent-encoded), see
85+
# https://github.com/phusion/passenger/blob/release-5.0.26/src/apache2_module/Hooks.cpp#L885
86+
# for the implementation as hooked up to an Apache web server. Code
87+
# in the indirector / HTTP layer which consumes this path, however, assumes
88+
# that it has already been unescaped, so it is unescaped here.
89+
if request.path
90+
URI.unescape(request.path)
91+
end
8392
end
8493

8594
# return the request body

spec/unit/indirector/catalog/compiler_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@
9494
@compiler.find(@request)
9595
end
9696

97+
it "should pass node containing percent character to the compiler" do
98+
node_with_percent_character = Puppet::Node.new "%6de"
99+
Puppet::Node.indirection.stubs(:find).returns(node_with_percent_character)
100+
Puppet::Parser::Compiler.expects(:compile).with(node_with_percent_character, anything)
101+
@compiler.find(@request)
102+
end
103+
97104
it "should extract and save any facts from the request" do
98105
Puppet::Node.indirection.expects(:find).with(@name, anything).returns @node
99106
@compiler.expects(:extract_facts_from_request).with(@request)

spec/unit/network/http/api/indirected_routes_spec.rb

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,17 @@
127127
expect(lambda { handler.uri2indirection("UPDATE", "#{master_url_prefix}/node/bar", params) }).to raise_error(ArgumentError)
128128
end
129129

130-
it "should URI unescape the indirection key" do
130+
it "should not URI unescape the indirection key" do
131131
escaped = URI.escape("foo bar")
132-
indirection, method, key, final_params = handler.uri2indirection("GET", "#{master_url_prefix}/node/#{escaped}", params)
133-
expect(key).to eq("foo bar")
132+
indirection, _, key, _ = handler.uri2indirection("GET", "#{master_url_prefix}/node/#{escaped}", params)
133+
expect(key).to eq(escaped)
134134
end
135135

136-
it "should pass through a proper environment param in a call to check_authorization" do
137-
handler.expects(:check_authorization).with(anything,
138-
anything,
139-
all_of(
140-
has_entry(:environment,
141-
is_a(Puppet::Node::Environment)),
142-
has_entry(:environment,
143-
responds_with(:name,
144-
:env))))
145-
handler.uri2indirection("GET", "#{master_url_prefix}/node/bar", params)
136+
it "should not unescape the URI passed through in a call to check_authorization" do
137+
key_escaped = URI.escape("foo bar")
138+
uri_escaped = "#{master_url_prefix}/node/#{key_escaped}"
139+
handler.expects(:check_authorization).with(anything, uri_escaped, anything)
140+
indirection, _, _, _ = handler.uri2indirection("GET", uri_escaped, params)
146141
end
147142

148143
it "should not pass through an environment to check_authorization and fail if the environment is unknown" do
@@ -153,6 +148,19 @@
153148
"#{master_url_prefix}/node/bar",
154149
{:environment => 'bogus'}) }).to raise_error(ArgumentError)
155150
end
151+
152+
it "should not URI unescape the indirection key as passed through to a call to check_authorization" do
153+
handler.expects(:check_authorization).with(anything,
154+
anything,
155+
all_of(
156+
has_entry(:environment,
157+
is_a(Puppet::Node::Environment)),
158+
has_entry(:environment,
159+
responds_with(:name,
160+
:env))))
161+
handler.uri2indirection("GET", "#{master_url_prefix}/node/bar", params)
162+
end
163+
156164
end
157165

158166
describe "when converting a request into a URI" do

spec/unit/network/http/rack/rest_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ def mk_req(uri, opts = {})
6565
expect(@handler.path(req)).to eq("/foo/bar")
6666
end
6767

68+
it "should return the unescaped path for an escaped request path" do
69+
unescaped_path = '/foo/bar baz'
70+
escaped_path = URI.escape(unescaped_path)
71+
req = mk_req(escaped_path)
72+
expect(@handler.path(req)).to eq(unescaped_path)
73+
end
74+
6875
it "should return the request body as the body" do
6976
req = mk_req('/foo/bar', :input => 'mybody')
7077
expect(@handler.body(req)).to eq("mybody")

0 commit comments

Comments
 (0)