hostguard

package
v0.0.0-...-5106b98 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DialPublicHost

func DialPublicHost(ctx context.Context, network, address string) (net.Conn, error)

DialPublicHost resolves and dials a host:port address only when all resolved addresses are public.

func DialPublicHostWithDialer

func DialPublicHostWithDialer(
	ctx context.Context,
	network string,
	address string,
	lookup func(context.Context, string) ([]net.IPAddr, error),
	dial func(context.Context, string, string) (net.Conn, error),
) (net.Conn, error)

DialPublicHostWithDialer is the testable implementation behind PublicDialer.

func IsBlockedHostnameLiteral

func IsBlockedHostnameLiteral(hostname string) bool

IsBlockedHostnameLiteral reports whether a hostname string is a blocked IP literal. Non-IP hostnames return false because they must be resolved separately.

func IsBlockedIP

func IsBlockedIP(ip net.IP) bool

IsBlockedIP reports whether an IP falls into blocked non-public or special-use ranges.

func ResolvePublicHost

func ResolvePublicHost(ctx context.Context, hostname string) ([]net.IPAddr, error)

ResolvePublicHost resolves a hostname once and returns vetted public IP addresses.

func ResolvePublicHostWithLookup

func ResolvePublicHostWithLookup(
	ctx context.Context,
	hostname string,
	lookup func(context.Context, string) ([]net.IPAddr, error),
) ([]net.IPAddr, error)

ResolvePublicHostWithLookup resolves a hostname once with the provided lookup function and returns vetted public IP addresses.

func ValidateResolvedPublicHost

func ValidateResolvedPublicHost(ctx context.Context, hostname string) error

ValidateResolvedPublicHost resolves a hostname and rejects blocked/private targets.

Types

type DestinationPolicy

type DestinationPolicy struct {
	AllowPrivateHosts bool
}

DestinationPolicy defines whether a connector may reach private addresses while always resolving the requested hostname and dialing a returned literal IP address.

func NewDestinationPolicy

func NewDestinationPolicy(allowPrivateHosts bool) DestinationPolicy

NewDestinationPolicy creates the shared destination policy used by connector transports.

func (DestinationPolicy) DialContext

func (p DestinationPolicy) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext resolves the requested destination once and dials a vetted literal address. Callers retain the original hostname in protocol configuration so TLS SNI and Host headers continue to identify the intended server.

func (DestinationPolicy) DialContextWithDialer

func (p DestinationPolicy) DialContextWithDialer(
	ctx context.Context,
	network string,
	address string,
	lookup func(context.Context, string) ([]net.IPAddr, error),
	dial func(context.Context, string, string) (net.Conn, error),
) (net.Conn, error)

DialContextWithDialer resolves and dials a destination through injectable lookup and dial functions so protocol adapters can prove that the socket never receives the hostname.

func (DestinationPolicy) Resolve

func (p DestinationPolicy) Resolve(ctx context.Context, hostname string) ([]net.IPAddr, error)

Resolve resolves a hostname under this policy and returns the literal addresses that may be used.

func (DestinationPolicy) ResolveWithLookup

func (p DestinationPolicy) ResolveWithLookup(
	ctx context.Context,
	hostname string,
	lookup func(context.Context, string) ([]net.IPAddr, error),
) ([]net.IPAddr, error)

ResolveWithLookup applies the policy to the supplied DNS lookup result without performing a second resolution, which prevents callers from validating one DNS answer and dialing another.

type PublicDialer

type PublicDialer struct {
	Dialer *net.Dialer
}

PublicDialer resolves and dials only public IP addresses for host:port targets.

func (PublicDialer) DialContext

func (d PublicDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext resolves the target host, rejects private/special-use addresses, and dials one of the vetted IPs so the caller cannot re-resolve a different address later.

Jump to

Keyboard shortcuts

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