netpolicy

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package netpolicy decides which hosts a run may contact. `sonde mcp` builds a Policy from its --allow-host patterns; the HTTP client checks both the host of every request URL and the address of every connection it opens against the same Policy, with the same normalization, so what a request names and where its bytes go cannot disagree.

Index

Constants

This section is empty.

Variables

View Source
var ErrDenied = errors.New("not in the host allowlist")

ErrDenied reports a host outside the allowlist.

Functions

func Normalize

func Normalize(host string) (string, error)

Normalize returns the canonical form of a host as written in a URL or a dial address: lowercase, without a trailing dot, IPv6 brackets or zone, and an address in its canonical text. Only plain ASCII names (letters, digits, '-' and '_' in dot-separated labels) are accepted: a resolver may read anything else differently than this package does (a '%' is cut here but not by the system resolver, a Unicode name is converted to punycode before it is dialed). A host that looks like a short or hexadecimal IPv4 form (127.1, 0x7f000001), which some resolvers read as an address, is an error too.

Types

type Policy

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

Policy is a parsed allowlist. A nil *Policy allows everything.

func Parse

func Parse(patterns []string) (*Policy, error)

Parse builds a Policy from patterns:

api.example.com        that name, any port
api.example.com:8443   that name and port
*.example.com          any subdomain of example.com (not example.com)
10.1.2.3, [::1]:8080   that address (port optional; IPv6 in brackets with a port)
10.0.0.0/8, fd00::/8   an address in that range
*                      every host

Names are case-insensitive and a trailing dot is ignored. Names are never resolved: an address or range pattern matches only hosts written as addresses.

func (*Policy) Allow

func (p *Policy) Allow(host, port string) error

Allow reports whether host (as written in a URL or dial address) and port may be contacted. The error wraps ErrDenied.

func (*Policy) AllowsAll

func (p *Policy) AllowsAll() bool

AllowsAll reports whether the policy is `*` (or nil).

Jump to

Keyboard shortcuts

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