ssrf

package
v0.16.21 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 6 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 ssrf provides shared SSRF guards for outbound transports.

Package ssrf provides shared Server-Side Request Forgery (SSRF) guards for outbound WebDAV / backup transports.

Both the admin settings handler (handler/admin) and the backup scheduler previously carried byte-identical copies of this logic under different names (rejectUnsafeWebdavDialHost / rejectUnsafeBackupWebdavDialHost, etc.). Centralizing it here keeps the two call sites from drifting: a fix to the unsafe-range predicate or the TOCTOU-aware dial check lands in one place.

Each call site passes its own allowPrivate flag so operator/test escape hatches (e.g. pointing a WebDAV backup at a localhost test server) remain independent per feature without coupling the two packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAllowedWebdavTargetHost

func IsAllowedWebdavTargetHost(host string, allowPrivate bool) bool

IsAllowedWebdavTargetHost applies hostname-level allow/deny rules before DNS resolution. A bare hostname is allowed (its IPs are checked at dial time by RejectUnsafeWebdavDialHost). Literal IP literals are allowed only when they are not in an unsafe range. "localhost" and *.localhost are always denied. allowPrivate=true permits all hosts (operator escape hatch).

func IsForbiddenSiteAddr added in v0.16.10

func IsForbiddenSiteAddr(addr netip.Addr) bool

IsForbiddenSiteAddr applies the product's site-upstream policy at dial time. It rejects link-local, multicast, unspecified/reserved, and explicit metadata addresses while preserving loopback, RFC1918, and IPv6 ULA connectivity.

func IsForbiddenSiteHostname added in v0.16.10

func IsForbiddenSiteHostname(host string) bool

IsForbiddenSiteHostname reports hostnames that are metadata service aliases independent of DNS. Literal IPs are classified by IsForbiddenSiteAddr. Loopback and RFC1918/ULA addresses deliberately remain allowed because Metapi supports operator-hosted upstreams on local networks.

func IsPrivateOrLoopbackLiteral

func IsPrivateOrLoopbackLiteral(host string) bool

IsPrivateOrLoopbackLiteral reports whether host is a literal IP address in a private, loopback, link-local, multicast, or unspecified range. This covers:

  • Loopback: 127.0.0.0/8, ::1
  • Link-local: 169.254.0.0/16 (incl. cloud metadata 169.254.169.254), fe80::/10
  • Private: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
  • Unspecified: 0.0.0.0/8, ::

Hostnames that are not literal IPs return false: DNS resolution for hostnames is deferred to the dial-time guard (RejectUnsafeWebdavDialHost) to avoid TOCTOU races (a hostname that resolves to a safe IP at validation time could resolve to a private IP by dial time, and vice versa).

func IsUnsafeAddr

func IsUnsafeAddr(addr netip.Addr) bool

IsUnsafeAddr reports whether an IP address falls in an unsafe range for outbound SSRF-sensitive traffic: unspecified, loopback, private, link-local unicast, link-local multicast, or multicast.

The whole 0.0.0.0/8 block is treated as unsafe, not just the exact unspecified address: RFC 5735 defines 0.0.0.0/8 as "this network", and several kernels/containers route it to the local stack. netip's IsUnspecified() only matches the all-zero address, so the first octet is checked explicitly to match the documented intent.

func RejectUnsafeWebdavDialHost

func RejectUnsafeWebdavDialHost(ctx context.Context, host string, allowPrivate bool) error

RejectUnsafeWebdavDialHost validates a host immediately before a network dial. It applies hostname-level allow/deny rules and then resolves the host to verify that none of the resolved IPs fall in an unsafe range, preventing the TOCTOU race where a hostname resolves to a safe IP at validation time but a private IP by dial time (and vice versa).

allowPrivate=true disables the guard entirely (operator escape hatch / test isolation for httptest servers on 127.0.0.1).

Types

type DialContextFunc added in v0.16.10

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

DialContextFunc matches net.Dialer's DialContext method.

func NewSiteDialContext added in v0.16.10

func NewSiteDialContext(resolver NetIPResolver, dial DialContextFunc) DialContextFunc

NewSiteDialContext returns a DNS-pinning DialContext for operator-configured site upstreams. Hostnames are resolved exactly once, every answer is checked, and the connection is made to the already-checked IP rather than asking the underlying dialer to resolve the hostname again. This closes the usual DNS rebinding / validation-to-dial window.

type NetIPResolver added in v0.16.10

type NetIPResolver interface {
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}

NetIPResolver is the subset of net.Resolver used by the site dial guard. It is intentionally injectable so tests can exercise DNS alias behavior without relying on public DNS.

Jump to

Keyboard shortcuts

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