safehttp

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 7 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 safehttp builds outbound HTTP clients that refuse to connect to non-public addresses. It is shared by every feature that fetches a URL an untrusted party can influence (CIMD documents, client jwks_uri, ...).

Index

Constants

This section is empty.

Variables

View Source
var ErrBlockedAddress = errors.New("safehttp: destination address is not publicly routable")

ErrBlockedAddress is returned when a fetch would connect to a non-public address (loopback, private, link-local, CGNAT, metadata).

Functions

func ClientWithDialer

func ClientWithDialer(timeout time.Duration, dialer *net.Dialer) *http.Client

ClientWithDialer is NewClient with a caller-supplied dialer, so tests can substitute a resolver while keeping the same transport hardening.

func GuardedControl

func GuardedControl(allowPrivate bool) func(network, address string, _ syscall.RawConn) error

GuardedControl returns a net.Dialer.Control function. It runs after DNS resolution on every connection attempt, so a rebinding resolver cannot swap in a private address after validation.

func IsBlockedIP

func IsBlockedIP(ip netip.Addr) bool

IsBlockedIP reports whether ip must never be the target of a guarded fetch.

func NewClient

func NewClient(timeout time.Duration, allowPrivate bool) *http.Client

NewClient builds the default fetch client: dial-time address guard, no proxy, no redirects, and the configured timeout.

Types

This section is empty.

Jump to

Keyboard shortcuts

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