Module: RubyProxyHeaders

Defined in:
lib/ruby_proxy_headers.rb,
lib/ruby_proxy_headers/excon.rb,
lib/ruby_proxy_headers/faraday.rb,
lib/ruby_proxy_headers/faraday.rb,
lib/ruby_proxy_headers/version.rb,
lib/ruby_proxy_headers/http_gem.rb,
lib/ruby_proxy_headers/httparty.rb,
lib/ruby_proxy_headers/net_http.rb,
lib/ruby_proxy_headers/typhoeus.rb,
lib/ruby_proxy_headers/connection.rb,
lib/ruby_proxy_headers/rest_client.rb

Defined Under Namespace

Modules: ExconIntegration, FaradayAdapter, FaradayIntegration, HTTPGem, NetHTTP, RestClient, Typhoeus Classes: Connection, HeaderMap, ProxyHeadersConnectionAdapter

Constant Summary collapse

INVALID_HEADER_NAME_RE =
/[\r\n\0]/
INVALID_HEADER_VALUE_RE =
/[\r\n\0]/
VERSION =
'0.3.0'

Class Method Summary collapse

Class Method Details

.proxy_connect_response_headers ⇒ Object

CONNECT response headers from the last Net::HTTP-based proxied HTTPS request on this thread.



43
44
45
# File 'lib/ruby_proxy_headers.rb', line 43

def self.proxy_connect_response_headers
  Thread.current[:ruby_proxy_headers_connect_headers]
end

.validate_connect_target!(host, port) ⇒ Object

Raises ArgumentError if +host+ or +port+ contain CR, LF, or NUL bytes that would allow HTTP request smuggling when interpolated into a CONNECT line.



60
61
62
63
64
65
66
67
68
69
# File 'lib/ruby_proxy_headers.rb', line 60

def self.validate_connect_target!(host, port)
  if INVALID_HEADER_VALUE_RE.match?(host.to_s)
    raise ArgumentError,
          "CONNECT target host contains invalid characters (CR, LF, or NUL): #{host.inspect}"
  end
  if INVALID_HEADER_VALUE_RE.match?(port.to_s)
    raise ArgumentError,
          "CONNECT target port contains invalid characters (CR, LF, or NUL): #{port.inspect}"
  end
end

.validate_header!(name, value) ⇒ Object

Raises ArgumentError if +name+ or +value+ contain CR, LF, or NUL bytes that would allow HTTP header injection in a raw CONNECT request.



49
50
51
52
53
54
55
56
# File 'lib/ruby_proxy_headers.rb', line 49

def self.validate_header!(name, value)
  if INVALID_HEADER_NAME_RE.match?(name.to_s)
    raise ArgumentError, "proxy CONNECT header name contains invalid characters (CR, LF, or NUL): #{name.inspect}"
  end
  if INVALID_HEADER_VALUE_RE.match?(value.to_s)
    raise ArgumentError, "proxy CONNECT header value contains invalid characters (CR, LF, or NUL): #{value.inspect}"
  end
end