excon 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5b23fd4372baad22a291604ac1177dede89a9e4a8b9caa1aa86019f4893b98d
4
- data.tar.gz: 54bb6046bf8e2359a75e6720b9d8d0ffbdb41dbeeea3a483b78d0e58a2653119
3
+ metadata.gz: 2ff4a819b128bfdfd7a8bca2a4f0d27ee25de1dccc82113edf290831913b3d36
4
+ data.tar.gz: cffe2d963e403f1a424692d12706b21d8f502902530b6b0c0a7c32d16b558d8c
5
5
  SHA512:
6
- metadata.gz: 6032a35accee4a3c447c61b2a1d8bac83352b6fd3c2eb18171f59942614983d5b17bcc18f55e051e4280008ff326acc65f93134f2cfb88d6ce18f604dd51b5ac
7
- data.tar.gz: 8dfd5595f225591adf29b9d4cba4740825e75b575d894c4a5ebdb3cad468fadefa9b980ca68e7a443a23cb6e04ef72cf457855c760e93b6894f74327674c6b17
6
+ metadata.gz: bd25fa62f4ad4d735fd8c1f3a9658ec2b59c52170298c315c5ee38068bc4d8155106d2af21337355d83ad63f82ac7359e4c9fcafc9c284f2a1cf3c0e291ad891
7
+ data.tar.gz: 8115339527863cbfa6b2660001720732d3c52687170e792fd79c89ca6c05f4539b0b00266fc3cb3632b06dfbff371435f7a539cb1305dfbcd66c761974140419
@@ -104,7 +104,7 @@ module Excon
104
104
  end
105
105
  else
106
106
  if @data.key?(:host) && @data[:host].nil?
107
- raise Excon::Error::InvalidParameter, "host is required for non-Unix connections; " \
107
+ raise Excon::Error::InvalidHost, "host is required for non-Unix connections; " \
108
108
  "the URL may be malformed (e.g. missing \"//\" after the scheme)"
109
109
  end
110
110
  @socket_key = "#{@data[:scheme]}://#{@data[:host]}#{port_string(@data)}"
@@ -124,16 +124,31 @@ module Excon
124
124
  # we already have data from a middleware, so bail
125
125
  return datum
126
126
  else
127
+ if include_unsafe_chars?(datum[:host].to_s)
128
+ raise Excon::Errors::InvalidHost, "host #{datum[:host].inspect} contains unsafe \"\\0\", \"\\n\" or \"\\r\""
129
+ end
130
+ if include_unsafe_chars?(datum[:method].to_s)
131
+ raise Excon::Errors::InvalidMethod, "method #{datum[:method].inspect} contains unsafe \"\\0\", \"\\n\" or \"\\r\""
132
+ end
133
+ if include_unsafe_chars?(datum[:path])
134
+ raise Excon::Errors::InvalidPath, "path #{datum[:path].inspect} contains unsafe \"\\0\", \"\\n\" or \"\\r\""
135
+ end
136
+ query = query_string(datum)
137
+ if include_unsafe_chars?(query)
138
+ raise Excon::Errors::InvalidQuery, "query contains unsafe \"\\0\", \"\\n\" or \"\\r\""
139
+ end
140
+
127
141
  socket(datum).data = datum
128
142
  # start with "METHOD /path"
129
143
  request = datum[:method].to_s.upcase + ' '
130
144
  if datum[:proxy] && datum[:scheme] != HTTPS
131
145
  request << datum[:scheme] << '://' << datum[:host] << port_string(datum)
132
146
  end
147
+
133
148
  request << datum[:path]
134
149
 
135
150
  # add query to path, if there is one
136
- request << query_string(datum)
151
+ request << query
137
152
 
138
153
  # finish first line with "HTTP/1.1\r\n"
139
154
  request << HTTP_1_1
@@ -197,7 +212,7 @@ module Excon
197
212
  end
198
213
  rescue => error
199
214
  case error
200
- when Excon::Errors::InvalidHeaderKey, Excon::Errors::InvalidHeaderValue, Excon::Errors::StubNotFound, Excon::Errors::Timeout
215
+ when Excon::Errors::InvalidParameter, Excon::Errors::StubNotFound, Excon::Errors::Timeout
201
216
  raise(error)
202
217
  when Errno::EPIPE
203
218
  # Read whatever remains in the pipe to aid in debugging
@@ -272,7 +287,7 @@ module Excon
272
287
  datum[:headers][host_key] ||= ''
273
288
  else
274
289
  if datum[:host].nil?
275
- raise Excon::Error::InvalidParameter, "host is required for non-Unix connections; " \
290
+ raise Excon::Error::InvalidHost, "host is required for non-Unix connections; " \
276
291
  "the URL may be malformed (e.g. missing \"//\" after the scheme)"
277
292
  end
278
293
  datum[:headers][host_key] ||= datum[:host] + port_string(datum)
data/lib/excon/error.rb CHANGED
@@ -52,9 +52,15 @@ or:
52
52
  end
53
53
  end
54
54
 
55
- class InvalidHeaderKey < Error; end
56
- class InvalidHeaderValue < Error; end
57
55
  class InvalidParameter < Error; end
56
+
57
+ class InvalidHeaderKey < InvalidParameter; end
58
+ class InvalidHeaderValue < InvalidParameter; end
59
+ class InvalidHost < InvalidParameter; end
60
+ class InvalidMethod < InvalidParameter; end
61
+ class InvalidPath < InvalidParameter; end
62
+ class InvalidQuery < InvalidParameter; end
63
+
58
64
  class Timeout < Error; end
59
65
  class ResponseParse < Error; end
60
66
 
data/lib/excon/utils.rb CHANGED
@@ -123,18 +123,23 @@ module Excon
123
123
  str.gsub(ESCAPED) { ::Regexp.last_match(1).hex.chr }
124
124
  end
125
125
 
126
+ # Detects NUL CR and/or LF as these are unsafe to include without escaping
127
+ def include_unsafe_chars?(str)
128
+ str.include?("\0") || str.include?("\n") || str.include?("\r")
129
+ end
130
+
126
131
  # Performs validation on the passed header hash and returns a string representation of the headers
127
132
  def headers_hash_to_s(headers)
128
133
  headers_str = +''
129
134
  headers.each do |key, values|
130
- if key.to_s.match?(/[\r\n]/)
131
- raise Excon::Errors::InvalidHeaderKey, "#{key.to_s.inspect} contains forbidden \"\\r\" or \"\\n\""
135
+ if include_unsafe_chars?(key.to_s)
136
+ raise Excon::Errors::InvalidHeaderKey, "header key #{key.to_s.inspect} contains unsafe \"\\0\", \"\\n\" or \"\\r\""
132
137
  end
133
138
 
134
139
  [values].flatten.each do |value|
135
- if value.to_s.match?(/[\r\n]/)
140
+ if include_unsafe_chars?(value.to_s)
136
141
  # Don't include the potentially sensitive header value (i.e. authorization token) in the message
137
- raise Excon::Errors::InvalidHeaderValue, "#{key} header value contains forbidden \"\\r\" or \"\\n\""
142
+ raise Excon::Errors::InvalidHeaderValue, "header #{key.to_s.inspect} value contains unsafe \"\\0\", \"\\n\" or \"\\r\""
138
143
  end
139
144
 
140
145
  headers_str << key.to_s << ': ' << value.to_s << CR_NL
data/lib/excon/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Excon
4
- VERSION = "1.11.0"
4
+ VERSION = "1.12.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dpiddy (Dan Peterson)