hostpin

package
v1.0.511 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hostpin decides whether an inner request on a TLS-inspected CONNECT tunnel names the destination the tunnel was authorized for (ADR-0052). It is one predicate, Pinned, over two strings. It holds no state, performs no I/O and does no logging.

Ownership: package main (inspect_host_pin.go, runInspectExchange) owns the exchange, the decision to refuse, the refusal counter, the log line and the block response. This package owns only the comparison and its refusal rules.

Why the comparison is its own owner

The pin's value rests on one invariant: whenever it answers "pinned", the authority the UPSTREAM receives is the destination policy authorized. Every defect found in it so far was a violation of that invariant reached through the comparison rather than around it: a value repaired by a shared helper while net/http serialized the unrepaired one. The rules are therefore written against the wire's own definition (httpguts.PunycodeHostPort and httpguts.ValidHostHeader, the helpers net/http and the HTTP/2 encoder apply) and are tested here against the real stdlib serialization, without the proxy.

Scope: a NAMED tunnel destination only

The anchor is the CONNECT authority, because that is the value policy evaluated; it is not the client's SNI. When the tunnel host is an IP literal the pin does not fire: a client that resolved the name itself legitimately CONNECTs to an address and names the origin in SNI and Host, and the proxy holds no name to compare against. An empty or unserializable inner authority is still refused in that case. The full statement of what this leaves open, and why a mismatch is refused with a 403, is in inspect_host_pin.go, which owns the gate.

Fail closed

A host that cannot be canonicalized on either side is refused, an empty host on either side is refused, and brackets that do not enclose an IP literal are refused. This is deliberately NOT internal/hostutil's StripHostPort behavior: that helper repairs bracketed and port-suffixed spellings for the matchers that read through it, and tightening it would change every one of those callers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pinned

func Pinned(innerHost, tunnelHost string) bool

Pinned reports whether an inner request's host names the same destination as the CONNECT target this tunnel was authorized for.

Both sides are reduced the same way — port and IPv6 brackets stripped, then IDNA-canonicalized — so the comparison cannot be defeated by a spelling the matchers would have folded anyway (case, a trailing dot, a U-label against the A-label the CONNECT carried, "host:443" against "host"). The port is NOT part of the comparison: the TCP connection already fixes it, so a port claim in the header cannot redirect anything.

An EMPTY inner host is REFUSED (Codex P1 on PR #1632, verified and correct). The first revision of this gate treated it as pinned, reasoning that it names no competing destination and that an origin requiring a Host would reject it on its own. Both halves of that were wrong, and the second half was the real error: it assumed the ORIGIN's behaviour instead of enforcing here, which is the same fail-open asymmetry this gate exists to remove.

Measured against the tree, not argued: runH1InspectLoop reads inner requests with http.ReadRequest, NOT through an http.Server, so the server's "missing required Host header" 400 never runs — ReadRequest accepts "GET / HTTP/1.1\r\n\r\n" and yields req.Host == "" with req.URL.Host == "". Request.Write then serializes that as a literal "Host: " and returns no error, so the Host-less request reached the upstream. A shared front end with a default or fallback virtual host (an nginx "server_name _", a CDN catch-all) answers such a request from that vhost — a destination policy never evaluated, with the scan verdicts and the log row still attributed to the CONNECT host. That is the very bypass this gate closes, arriving through the one branch that waved it through.

Refusing costs nothing a client is entitled to. It named its destination in the CONNECT line, so it is not being asked for anything it has not already supplied, and no origin can route a Host-less HTTP/1.1 request to a specific vhost anyway. The refusal is taken BEFORE the IP-literal scope skip below, because the default-vhost concern does not depend on whether the CONNECT target was a name or an address.

The entitlement rests on the CONNECT line ALONE, deliberately — not on "and again in the TLS SNI", which an earlier revision of this comment claimed (CodeRabbit on PR #1632, correct). Because the refusal above covers an IP-literal CONNECT target, and RFC 6066 §3 forbids a literal IPv4/IPv6 address in the SNI HostName, there is no SNI name to appeal to in exactly the case this branch was extended to cover; SNI is optional besides. The CONNECT authority is the authorizing value and the only one always present, which is the same reason the pin anchors on it rather than on the SNI (see "Scope" in the package comment).

Substituting the authorized authority instead of refusing was considered and rejected: it would have the gateway synthesize a Host the client never sent, changing request semantics to make a malformed request succeed. Fail closed.

An empty TUNNEL host is NOT pinned. It means this exchange has no recorded authorized destination, and forwarding a client-chosen host in that state is exactly what this gate exists to prevent. It is unreachable in production: handleTunnelInspect appends ":443" when the CONNECT authority carries no port, so SplitHostPort always succeeds and hostOnly is non-empty for any CONNECT that got far enough to dial an upstream.

An IP-LITERAL tunnel host is pinned — see "Scope" in the package comment — but only once the empty-inner-host refusal above has run. The check is on the TUNNEL side only: an inner host that is an IP literal while the tunnel names a host is still a mismatch, because no conforming client sends an address in Host for a connection it opened to a name.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL