Skip to content

HTTPS proxy connection (p_use_ssl/proxy_use_ssl) does not verify the proxy's certificate #308

Duplicate

Description

@gsar

When connecting to a destination over TLS through a TLS proxy (an "HTTPS proxy"), enabling p_use_ssl encrypts the client→proxy hop but does not authenticate the proxy's certificate. The proxy TLS socket is built with no SSLContext and no post-connection check, so it defaults to VERIFY_NONE. This makes the proxy hop MITM-able, which matters because the Proxy-Authorization (Basic) credential is written over that socket in the CONNECT request.

Setup

Either of the documented ways to enable a TLS proxy:

  proxy = Net::HTTP.Proxy('proxy.example.com', 8080, 'user', 'pass', true)  # 5th arg -> @proxy_use_ssl
  http  = proxy.new('login.example.com', 443)
  http.use_ssl = true
  # ...or Net::HTTP.new(addr, port, p_addr, p_port, p_user, p_pass, p_no_proxy, true)
  http.get('/')

What happens

In Net::HTTP#connect, when @proxy_use_ssl is set, the proxy socket is wrapped as:

  proxy_sock = OpenSSL::SSL::SSLSocket.new(s)   # no SSLContext passed
  ssl_socket_connect(proxy_sock, @open_timeout)
  # ... then CONNECT + "Proxy-Authorization: Basic <creds>" is written to proxy_sock

SSLSocket.new(s) with no context uses a default context (verify_mode effectively VERIFY_NONE), and there is no post_connection_check on proxy_sock— the only post_connection_check in connect targets @address (the destination). So:

  • The destination cert is verified (via @ssl_context + post_connection_check(@address)). ✅
  • The proxy cert is neither verified nor hostname-checked. ❌

A MITM on the client→proxy path can therefore present any certificate, terminate the TLS, and read the Proxy-Authorization credential — the same credential exposure that enabling proxy TLS is meant to prevent.

Expected

The proxy TLS connection should verify the proxy certificate by default (use an SSLContext with VERIFY_PEER and run post_connection_check against the proxy host), consistent with how the destination connection is verified. At minimum there should be a way to supply verification settings (CA store, verify_mode, hostname) for the proxy connection distinct from the destination's.

Environment

  • Ruby 4.0.5
  • net-http 0.9.1
  • Reproduced by reading lib/net/http.rb#connect (the if @proxy_use_ssl branch) — the proxy SSLSocket is built without a context and gets no post_connection_check.

Related

Activity

  1. thesecguy45 commented on Nov 2, 2026

    @thesecguy45

    Reproduced this end-to-end on released net-http 0.10.0 (Ruby 3.2.3), in case a runnable case helps move it along. The issue describes the defect from source; this is it actually executing, plus a control.

    Setup: an "interceptor" listening on loopback presenting a self-signed certificate for CN=totally-unrelated.example — not the proxy's name, not trusted by anything.

    http = Net::HTTP.new("example.com", 443, "127.0.0.1", port,
                         "proxyuser", "sup3r-s3cret-proxy-pw", nil, true)  # p_use_ssl
    http.use_ssl = true
    http.start { }

    What the interceptor received:

    CONNECT example.com:443 HTTP/1.1
    Host: example.com:443
    Proxy-Authorization: Basic cHJveHl1c2VyOnN1cDNyLXMzY3JldC1wcm94eS1wdw==
    
    decoded -> proxyuser:sup3r-s3cret-proxy-pw
    

    The client does raise OpenSSL::SSL::SSLError a moment later — but that is the origin handshake failing, after the proxy credentials are already on the wire. The failure that users would notice happens strictly too late to protect them.

    Control, same certificate, but with a properly configured verifying context (VERIFY_PEER + verify_hostname):

    verifying client rejected the peer: OpenSSL::SSL::SSLError
    bytes the interceptor received: nil
    

    Nothing is sent. That contrast is the whole bug: the proxy leg is the one hop that gets no context.

    One thing I did not see mentioned here: the vendored copy under RubyGems has the same line.

    lib/rubygems/vendor/net-http/lib/net/http.rb:1712
        proxy_sock = OpenSSL::SSL::SSLSocket.new(s)
    

    So a fix in this repository will need mirroring there, or gem keeps the behaviour.

    I checked p_use_ssl is present in every net-http release I could test — 0.6.0, 0.7.0, 0.8.0, 0.9.0 and 0.10.0 — so this is not limited to the newest gem.

    Happy to share the reproducer script; it is about 90 lines and needs no network.

  2. orien commented on Nov 27, 2026

    @orien
    Contributor

    The same credential exposure happens when the proxy comes from the environment. With http_proxy=https://user:pass@proxy:port, net-http ignores the https scheme and connects to the proxy over plain TCP, so the CONNECT request and the Proxy-Authorization header go out in cleartext. In this case no TLS is used for the proxy at all, so the fix in #368 does not change it.

    Reproduction on net-http 0.10.0 (master at e686ee5), Ruby 4.0.10, with a plain TCP listener standing in for the proxy:

    require 'net/http'
    require 'socket'
    
    server = TCPServer.new('127.0.0.1', 0)
    port = server.addr[1]
    received = Thread.new do
      c = server.accept
      buf = +''
      buf << c.readpartial(4096) until buf.include?("\r\n\r\n")
      c.close
      buf
    end
    
    ENV['http_proxy'] = "https://euser:epass@127.0.0.1:#{port}"
    http = Net::HTTP.new('origin.example', 443)
    http.use_ssl = true
    http.max_retries = 0
    begin
      http.get('/')
    rescue => e
      puts "client: #{e.class}"
    end
    puts received.value

    Output:

    client: EOFError
    CONNECT origin.example:443 HTTP/1.1
    Host: origin.example:443
    Proxy-Authorization: Basic ZXVzZXI6ZXBhc3M=
    

    proxy_uri takes the host, port, user and password from find_proxy, but nothing sets @proxy_use_ssl from the URL scheme. I'd expect an https:// proxy URL to enable TLS to the proxy, with the same certificate checks #368 adds.

  3. rhenium commented on Nov 27, 2026

    @rhenium
    Member

    Closing as duplicate of #212. The default looks clearly wrong, but HTTPS proxy support is currently unusable to begin with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions