urlguard

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 11 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 urlguard is the canonical SSRF guard for every outbound fetch abcd makes.

abcd fetches URLs from two places — memory ingest takes one from the operator, and the citation refresh takes them from committed documentation — and in both the address is attacker-influenceable content. A guard that lives inside one caller is a guard the next caller reimplements slightly differently, which is exactly how a metadata endpoint ends up reachable from the second fetch path. So the predicate, the name check, and the connect-time re-check live here once, and every fetcher composes them.

The address predicate is a PARAMETER of the name check and the dial control rather than a hard-wired call, for one reason: a fetch path can then be exercised against an httptest server (which binds loopback) by relaxing the predicate in the test alone, while the shipped default — BlockedIP — is never relaxed anywhere. A guard nobody can test end-to-end is a guard nobody trusts.

Download (download.go) composes them into the one transport rule a download of release bytes holds to, so abcd's own update path and the tool installer decide which hosts they may reach in one place.

Index

Constants

View Source
const MaxRedirects = 8

MaxRedirects bounds the redirects one download follows.

Variables

View Source
var CAOverrides = []string{"SSL_CERT_FILE", "SSL_CERT_DIR"}

CAOverrides are the variables crypto/x509 reads when it loads the system root pool.

Functions

func BlockedIP

func BlockedIP(ip net.IP) bool

BlockedIP reports whether ip is in a range that must never be fetched: loopback (127/8, ::1), link-local (169.254/16, fe80::/10 unicast and multicast), private (10/8, 172.16/12, 192.168/16, fc00::/7 via net.IP.IsPrivate), the unspecified address, any multicast address, the reserved non-private IPv4 ranges above — notably CGNAT 100.64/10 — and the fixed provider platform magic IPs in public space (platformMagicV4). This is what keeps cloud metadata endpoints (e.g. 169.254.169.254, 168.63.129.16) and abcd-lint:allow internal services out of reach.

func CheckHost

func CheckHost(host string) error

CheckHost refuses a host that is an internal/metadata name or that resolves to a blocked address, under the shipped default policy.

func CheckHostWith

func CheckHostWith(host string, blocked func(net.IP) bool) error

CheckHostWith is CheckHost with the address predicate supplied by the caller. It runs before the initial request and on every redirect hop. An IP literal is checked directly (no DNS); a name is rejected outright when it is an *.internal / metadata name, otherwise every resolved address is checked.

The NAME half is policy-independent: an *.internal or metadata name never gets as far as an address, so no predicate can wave it through.

func DialControl

func DialControl(blocked func(net.IP) bool) func(network, address string, c syscall.RawConn) error

DialControl builds a net.Dialer Control hook that re-checks the ACTUAL resolved IP of every dialled connection, closing the DNS-rebinding gap between a name-based guard and the transport's own resolution.

func OverrideFreeRoots added in v0.16.0

func OverrideFreeRoots() *x509.CertPool

OverrideFreeRoots loads the system root pool with the CA overrides out of the environment for the load alone, then puts back exactly what it took out, so an environment variable never chooses which certificate authorities a download trusts and the caller's environment is left as it was. crypto/x509 loads that pool once per process: when this is the first load, the process's default pool ignores the overrides from then on too, while the variables stay set for anything the process starts. A nil pool (SystemCertPool error) falls back to the platform default.

Types

type Download added in v0.16.0

type Download struct {
	// Client is the pinned client. A request made through it must first pass
	// Admit: the client checks redirects, not the URL it was handed.
	Client *http.Client
	// contains filtered or unexported fields
}

Download is the one transport rule every download of release bytes holds to, abcd's own update path and the tool installer alike: https only, the environment never chooses where the client connects (no proxy, and a root pool the caller loaded with the CA overrides held out), the address policy on every dial and every redirect, every request and every redirect only to a host the download's purpose names, and a bound on redirects and on time. A size bound is the caller's, since it differs by what is read.

func NewDownload added in v0.16.0

func NewDownload(blocked func(net.IP) bool, allowHTTP bool, timeout time.Duration, rootCAs *x509.CertPool, hosts ...string) *Download

NewDownload builds the transport. blocked is the address policy (nil allows every address, for a loopback test server); rootCAs is the trust pool (nil is the platform default); hosts are the only hosts a request or a redirect may name.

func (*Download) Admit added in v0.16.0

func (d *Download) Admit(u *url.URL) error

Admit refuses a URL that is not https or names a host outside the download's purpose.

func (*Download) AllowHost added in v0.16.0

func (d *Download) AllowHost(host string)

AllowHost adds a host a request or a redirect may name. It is called while the download is being set up, before its first request: the host set is read, unlocked, by the client's redirect check.

func (*Download) Sibling added in v0.16.0

func (d *Download) Sibling(hosts ...string) *Download

Sibling is a download for another purpose over the same pinned transport, root pool and address policy, reaching only hosts: a purpose's hosts are its own, so one purpose's requests and redirects never reach another's.

Jump to

Keyboard shortcuts

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