outboundpolicy

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package outboundpolicy defines the shared destination boundary for outbound network clients.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidURL reports a URL that cannot be used as an outbound destination.
	ErrInvalidURL = errors.New("outbound policy: invalid destination URL")
	// ErrInsecureTransport reports HTTP used outside an explicitly trusted origin or loopback allowance.
	ErrInsecureTransport = errors.New("outbound policy: HTTPS is required for untrusted destinations")
	// ErrBlockedDestination reports an address outside the configured destination policy.
	ErrBlockedDestination = errors.New("outbound policy: destination is blocked")
)

Functions

func IsExplicitLoopbackHost

func IsExplicitLoopbackHost(host string) bool

IsExplicitLoopbackHost recognizes literal and reserved-name loopback destinations.

func NewHTTPClient

func NewHTTPClient(base *http.Client, policy Policy, timeout time.Duration, maxRedirects int) *http.Client

NewHTTPClient clones a client and installs URL, redirect, and dial-time policy. A custom non-*http.Transport RoundTripper remains the explicit owner of its connection boundary.

func SameOrigin

func SameOrigin(left, right *url.URL) bool

SameOrigin compares normalized scheme, hostname, and effective port.

Types

type Dialer

type Dialer struct {
	// contains filtered or unexported fields
}

Dialer validates the complete DNS answer immediately before connecting to a pinned IP.

func NewDialer

func NewDialer(policy Policy, resolver Resolver, dialer NetworkDialer) Dialer

NewDialer constructs a policy-enforcing dialer.

func (Dialer) DialContext

func (d Dialer) DialContext(ctx context.Context, network string, endpoint string) (net.Conn, error)

DialContext resolves, validates, and connects without performing a second hostname lookup.

type NetworkDialer

type NetworkDialer interface {
	DialContext(context.Context, string, string) (net.Conn, error)
}

NetworkDialer establishes one connection to an already-approved IP address.

type Policy

type Policy struct {
	// contains filtered or unexported fields
}

Policy validates URL and resolved-address destinations. Values are immutable after construction.

func New

func New(allowLoopback bool) Policy

New returns a public-network policy, optionally allowing explicit loopback hosts.

func (Policy) IsTrustedOrigin

func (p Policy) IsTrustedOrigin(destination *url.URL) bool

IsTrustedOrigin reports whether a URL matches one exact operator-owned origin.

func (Policy) ValidateResolvedAddresses

func (p Policy) ValidateResolvedAddresses(addresses []netip.Addr, host string, port string) error

ValidateResolvedAddresses rejects a complete DNS answer when any address violates the policy for the exact destination host and port.

func (Policy) ValidateURL

func (p Policy) ValidateURL(destination *url.URL) error

ValidateURL applies scheme, origin, and literal-address policy before a request is sent.

func (Policy) WithCredentialOrigin

func (p Policy) WithCredentialOrigin(raw string) (Policy, error)

WithCredentialOrigin returns a copy that permits credential forwarding to one exact public HTTPS origin without granting access to private resolved addresses.

func (Policy) WithTrustedOrigin

func (p Policy) WithTrustedOrigin(raw string) (Policy, error)

WithTrustedOrigin returns a copy that permits one exact operator-owned HTTP(S) origin, including its resolved private addresses and credential forwarding. The URL must not contain credentials or a fragment.

type Resolver

type Resolver interface {
	LookupNetIP(context.Context, string, string) ([]netip.Addr, error)
}

Resolver resolves all IP addresses for one outbound hostname.

Jump to

Keyboard shortcuts

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