Web Proxy / Caching Fundamentals Series

🔗 Understanding the CONNECT Method From a Top 1% Perspective — Why a Proxy Can Relay HTTPS Traffic Without Ever Seeing Its Contents, and the Decisive Difference From SSL Inspection

Introduction

This article is part of the Top 1% Series Complete Article Guide, and article 3.1 in the Web Proxy / Caching Fundamentals Series.

Prerequisite Knowledge

Getting the Big Picture

HTTP has a special method called CONNECT, whose purpose is fundamentally different from GET or POST. When a client accesses an HTTPS site through a proxy, it first sends a request like CONNECT destination.example.com:443 HTTP/1.1 to the proxy. This is a request to “relay a TCP connection to this hostname and port” — not a request to forward an HTTP request at all. Once the proxy receives this request, it establishes a raw TCP connection to the specified destination, and from that point on becomes a simple tunnel that keeps relaying the byte stream flowing between the client and server, without ever understanding its meaning. From here, a TLS handshake takes place between the client and proxy, and between the proxy and server, establishing an encrypted connection — but the proxy itself never holds the key to that encrypted connection, so it can’t read the contents at all.

sequenceDiagram
    participant Client as Client
    participant Proxy as Proxy
    participant Server as Destination Server
    Client->>Proxy: CONNECT destination.example.com:443 HTTP/1.1
    Proxy->>Server: Establishes a TCP connection
    Proxy->>Client: HTTP/1.1 200 Connection Established
    Note over Client,Server: From here, the proxy becomes a simple<br/>byte-stream relay with no understanding of the content
    Client->>Server: TLS handshake + encrypted traffic<br/>(the proxy just lets it pass through)

Deep Dive Into the Fundamentals

Why URL-Path-Level Access Control Isn’t Possible for HTTPS Sites

The URL-level access control you experienced in the Squid hands-on relied on the premise that the proxy can read the HTTP request’s content (the request line, GET /path/to/page HTTP/1.1). But once a tunnel is established via the CONNECT method, the proxy can’t see the encrypted traffic’s contents at all, and has no way of knowing the actual HTTP request (the full URL, including the path) the client is sending to the server. All the proxy can ever know is the destination hostname and port number, handed over at the time of the CONNECT request. Because of this, access control for HTTPS sites, by default, only ever works at the “hostname” level — the finer-grained control possible with HTTP, “allow or deny only this specific path on this host,” can’t be achieved with a CONNECT tunnel alone.

The Relationship With TLS's SNI (Server Name Indication)

In a setup like a transparent proxy, where the client never explicitly sends a CONNECT request at all, the proxy instead reads the destination hostname from a field called SNI (Server Name Indication), sent in plain text at the very start of the TLS handshake. The information available from SNI is also just the hostname, so just as with the CONNECT method, path-level control isn’t possible. The transparent proxy covered in the hands-on building a transparent proxy also relies on this same SNI-based, hostname-level control, when it comes to HTTPS sites.

The CONNECT Method Also Requires Proxy Authentication

The 407 status code covered in how proxy authentication works gets returned not just for ordinary HTTP requests, but for CONNECT requests too, in the same way. When a proxy is configured to require authentication, the client first sends a CONNECT request, receives a 407 from the proxy, and resends the CONNECT request with credentials attached. The tunnel only ever gets established once authentication completes, so this prevents the scenario where an unauthenticated client could access any HTTPS site without limit, through the proxy.

What a Pro Sees Here (Top 1% Understanding)

A CONNECT Tunnel and SSL Inspection Are Two Entirely Different Operating Modes

As the explanation so far makes clear, a blind tunnel via the CONNECT method is the proxy’s default behavior. SSL inspection, by contrast, is an entirely different operating mode, where the proxy deliberately re-establishes a separate TLS session with the client, and another separate one with the server, decrypting and inspecting the encrypted traffic’s contents. Performing SSL inspection requires getting the client to trust the certificate the proxy presents (installing an internal CA’s root certificate, for instance) — without doing this, the proxy stays in its CONNECT-tunnel state, unable to see the contents at all. The misconception “deploying a proxy automatically lets you inspect HTTPS contents too” comes from not understanding that the CONNECT method is the default behavior, and SSL inspection is a separate mechanism that must be explicitly enabled.

Common Misconceptions and Pitfalls

Troubleshooting Perspective

  1. HTTP sites can be controlled at the URL path level, but HTTPS sites can’t be controlled at the same granularity: Check whether SSL inspection is enabled. If it isn’t, re-examine your requirements with the premise that the CONNECT method’s default behavior only allows hostname-level control.
  2. A proxy authentication popup appears when accessing an HTTPS site: This is the 407 response to a CONNECT request — the same behavior as the ordinary proxy authentication flow.
  3. After enabling SSL inspection, a specific application alone started getting connection errors: Check whether that application is rejecting the certificate the proxy presents, through a mechanism like certificate pinning.

Summary

Takeaways to Apply Today

  1. When considering access control for HTTPS sites, make explicit whether hostname-level control is sufficient, or path-level control is actually needed — and if it is, consider introducing SSL inspection.
  2. Drop the assumption “deploying a proxy automatically lets you see HTTPS contents too,” and keep in mind that the CONNECT method and SSL inspection are two separate operating modes.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).