Skip to content

http: a shared outbound destination guard (public-address classification and dial-time Control) #367

Closed

Description

@patdowney

Why this issue

Three services connect outbound to destinations that an untrusted party can influence, and each decides "is this address allowed?" on its own. connect has two guards that classify addresses differently, and eventbroker's webhook delivery has none. This is a shared concern that belongs in dioad/net, which the shared-extraction placement guide assigns connection primitives to.

It comes from dioad/eventbroker#108 (candidate X1, driven by row E15).

What exists today

Where What it does Polarity
connect sdk/agent/server/httpreverseproxy/validation.go (AddressValidator) A list of allowed CIDRs, defaulting to RFC 1918, loopback, IPv6 ULA and link-local. Blocks 169.254.0.0/16 unless allow-cloud-metadata is set. ValidateURL is a construction-time check; DialContext re-checks every resolved address in a net.Dialer.Control hook, so rebinding is covered. allow only listed (private) ranges
connect sdk/agent/server/socks5/policy.go (isPublic, destinationPolicy.control) Refuses anything that is not a public address: loopback, private, link-local, multicast, unspecified, plus a list of special-use prefixes (192.0.0.0/24, 198.18.0.0/15, 240.0.0.0/4, documentation ranges, Teredo) and NAT64 unwrapping. Also an allowed-ports list. Enforced in a Control hook. deny non-public
eventbroker pkg/webhook/validation.go, manager.go Create-time validation rejects only a literal unspecified or multicast IP, and explicitly allows loopback. Hostnames are not resolved. The delivery http.Client has no dial-time check and no CheckRedirect. none

So the two connect guards are both dial-time and both sound, but they answer the same question differently (for example only socks5 unwraps NAT64 and knows the special-use ranges), and eventbroker lets anyone who can create a webhook reach *.internal services or 169.254.169.254.

Proposal

A small, well-tested package in dioad/net. Shape is illustrative, to be settled in review:

// IsPublicAddress reports whether addr is a public internet address: not
// loopback, private (including IPv6 ULA, so Fly's private network),
// link-local (including cloud metadata), multicast, unspecified or in a
// special-use range. IPv4-mapped and NAT64 addresses are judged by the IPv4
// address they carry.
func IsPublicAddress(addr netip.Addr) bool

// DestinationPolicy decides which destinations a client may connect to.
type DestinationPolicy struct {
	// AllowPrefixes are exceptions to the default deny of non-public addresses.
	AllowPrefixes []netip.Prefix
	// OnlyPrefixes, when set, allows only these ranges (connect's reverse proxy).
	OnlyPrefixes []netip.Prefix
	// AllowedPorts, when set, restricts destination ports.
	AllowedPorts []int
}

// Control is a net.Dialer.Control hook: it checks the numeric address after
// name resolution and before the socket connects.
func (p DestinationPolicy) Control(network, address string, c syscall.RawConn) error

// Dialer and Transport helpers wire it up, with a redirect limit and a scheme check.

Design notes:

  • Enforce at the socket, after resolution, so it covers redirects, DNS rebinding and a hostname that resolves to several addresses. A create-time check is a convenience only.
  • A kept-alive connection is not re-checked per request; that is correct, as connect's comment explains.
  • Default is deny non-public with explicit allow-list exceptions; OnlyPrefixes keeps connect's reverse-proxy semantics expressible.
  • A config struct with mapstructure and desc tags and a Check(*configcheck.Collector), like OperationsConfig and CORSConfig, so services take it under the same keys.
  • Return a typed error (ErrDestinationDenied) so callers can map it to a validation error or a refused request.

Consumers and migration

  1. eventbroker adopts it for webhook delivery (E15 in build(deps): bump github.com/prometheus/client_golang from 1.17.0 to 1.18.0 #108). Whether any production subscriber is on a private address decides the default allow-list; the owner's current belief is that none are public.
  2. connect moves both guards onto it, keeping their config keys (separate issue in dioad/connect).
  3. Any other service that makes outbound calls on a caller's behalf.

Acceptance criteria

  • Table tests over address classes: loopback, RFC 1918, CGNAT, link-local, 169.254.169.254, IPv6 ULA and link-local, multicast, unspecified, IPv4-mapped IPv6, NAT64 wrapping a private address, each special-use prefix, and ordinary public addresses.
  • Dial-time tests with local listeners: a loopback destination is refused; an allow-listed one is permitted; a redirect to a denied address is refused; a hostname that resolves to a denied address is refused (use a custom resolver).
  • connect's existing socks5 and reverse-proxy tests pass unchanged when they move onto it.
  • make verify with GOWORK=off, no replace.

Related

🤖 Generated with Claude Code

https://claude.ai/code/session_01SS4MAwAn85D1gkEzLtjYaZ

Activity

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