MITM vs SNI egress proxies: what each can see

By the CapyShield team · · 5 min read

In short

An SNI-only egress proxy sees the CONNECT target, the TLS SNI name and how many bytes are sent, so it can enforce host allowlists but cannot see secrets inside requests. A MITM proxy terminates TLS with a locally trusted CA and inspects URLs, headers and bodies, at the cost of trusting that CA and breaking certificate-pinning clients. Fail-open keeps builds running when inspection fails; fail-closed blocks anything that could not be inspected.

Every egress proxy that handles HTTPS has to pick between two designs. An SNI-only proxy looks at where a TLS connection is going and passes the encrypted bytes through untouched. A MITM proxy terminates TLS, reads the request, and opens its own connection upstream. The choice decides what you can detect, what can break, and what happens when inspection fails. This post walks through both, using the CapyShield CLI's sni and mitm modes as a concrete example.

What can an SNI-only egress proxy see?

Less than people expect, but enough for host-level policy. When a client uses an HTTP proxy for HTTPS, it first sends CONNECT host:443 (defined in RFC 9110), and the proxy opens a tunnel. The client then starts a TLS handshake inside that tunnel, and its ClientHello carries the Server Name Indication extension (RFC 6066) in plaintext. So an SNI proxy knows:

  • the CONNECT target host and port;
  • the SNI name in the ClientHello, which should match it;
  • how many bytes the client sends, and when.

It cannot see the URL path, headers or body. A request to an allowed host that carries your AWS key in its body looks exactly like any other request to that host. In SNI mode, a policy can only ever be about hosts and byte counts.

Comparing the CONNECT target with the SNI name is still worth doing: a mismatch is the classic sign of domain fronting, where a client connects to an allowed host while asking for a different one. Encrypted Client Hello (ECH), now being standardized at the IETF, will hide the real SNI from on-path observers. A local forward proxy still sees the CONNECT target, so host policy keeps working, but SNI cross-checks lose their value where ECH is used.

What does a MITM egress proxy add?

Everything inside the request. The proxy completes the TLS handshake with the client itself, presenting a certificate for the requested host signed by a local certificate authority the client has been told to trust. It then reads each HTTP request in clear, decides, and forwards allowed requests over a fresh TLS connection whose upstream certificate it verifies against the public roots.

That unlocks the checks that actually catch exfiltration:

  • known credential formats in the URL, headers or body;
  • values of your own sensitive environment variables, plain or encoded;
  • the Host header compared with the tunnel target, which is domain fronting one layer up;
  • the difference between a token in an Authorization header to its own API (normal) and the same token in a body or to another host (a leak).

The cost is trust and compatibility. The local CA has to be trusted by the client, which is a real security decision. CapyShield injects it only into the wrapped process through variables such as NODE_EXTRA_CA_CERTS, SSL_CERT_FILE, REQUESTS_CA_BUNDLE and GIT_SSL_CAINFO, and never into the system trust store, so nothing else on the machine is affected. Clients that pin certificates will refuse the local certificate no matter what; list those in tls_bypass_hosts and they fall back to SNI handling.

Which mode should you use?

Use SNI when you want host control with negligible overhead, and MITM when you need to see payloads.

  • SNI is the right default for discovering what a build talks to and for enforcing an allowlist. Unknown hosts are blocked, and max_outbound_bytes can still cut a tunnel to a non-allow-listed host that sends too much.
  • MITM is what you need to catch a secret sent to a host you otherwise allow, such as github.com, which serves content anyone can upload and so can carry exfiltrated data too. It is also the only way to know for sure what a piece of telemetry actually contains.

Switching is one flag, or one config key:

terminal
# host policy and byte counts only
capyshield guard --config capyshield.yaml --tls sni -- npm ci

# full request inspection
capyshield guard --config capyshield.yaml --tls mitm -- npm ci
yaml
egress:
  tls_inspection: mitm
  tls_bypass_hosts: ["*.apple.com"]

On overhead: the CapyShield README reports full inspection adding about 0.11 ms at p95 for an empty body and 1.47 ms for a 64 KB body, measured on an Apple Silicon laptop. MITM mode adds TLS termination on top; SNI mode only parses the ClientHello and splices bytes.

Should an egress proxy fail open or fail closed?

It depends on whether a silent gap or a broken build costs you more. Inspection can fail for ordinary reasons: a client sends non-TLS bytes inside a CONNECT tunnel, a certificate can't be generated for an odd hostname, or the proxy itself can't start. The proxy then has to choose.

  • Fail open lets the traffic through uninspected. Builds keep working, but whatever couldn't be inspected also couldn't be stopped.
  • Fail closed blocks anything it couldn't inspect. Nothing slips past, and an unusual but legitimate client will break until you handle it.

CapyShield makes the choice explicit, separate from whether policy violations are blocked:

  • audit: violations are logged and allowed; inspection failures are allowed.
  • enforce_fail_open: violations are blocked; inspection failures are allowed, and if the proxy can't start the command runs unguarded with a warning.
  • enforce_fail_closed: violations and inspection failures are both blocked.

Concretely, in SNI mode a tunnel that doesn't start with a TLS ClientHello within 3 seconds is blocked under enforce plus fail_closed and allowed otherwise. In MITM mode, if a leaf certificate can't be generated, the connection falls back to an SNI tunnel under fail_open and is blocked under fail_closed.

terminal
capyshield guard --mode enforce --fail-mode fail_closed --tls mitm -- npm ci

A reasonable path: run capyshield watch first (it forces audit and fail-open), turn what you see into a policy with --emit-policy, enforce with fail-open while you tune it, and move CI to fail-closed once a few runs come back clean.

What can neither mode see?

Traffic that doesn't go through the proxy. Both designs here are forward proxies set through HTTP_PROXY, HTTPS_PROXY and ALL_PROXY. Tools like npm, pip, uv, curl, git and most SDKs honor those variables; code that deliberately opens raw sockets does not. For a hard boundary, run the command in a container or network namespace whose only route out is the proxy. The full decision flow, with diagrams, is in how CapyShield works, and the docs cover setting it up in CI.

Frequently asked questions

What can an SNI-only proxy see in HTTPS traffic?
The CONNECT target host and port, the SNI name in the TLS ClientHello, and byte counts. It cannot see URL paths, headers or request bodies.
When do you need a MITM egress proxy?
When you need to catch secrets sent to hosts you otherwise allow, such as an AWS key in a request body to github.com. Host-level policy alone cannot see that.
What is the difference between fail open and fail closed?
When a connection can't be inspected, fail open lets it through and fail closed blocks it. Fail open protects build reliability; fail closed guarantees nothing uninspected gets out.
Does CapyShield install its CA into the system trust store?
No. In mitm mode the local CA is injected only into the wrapped process through variables such as NODE_EXTRA_CA_CERTS and SSL_CERT_FILE, never into the system trust store.

Sources