netguard

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package netguard makes outbound HTTP requests to user-supplied URLs (outgoing webhooks, the audit stream) safe from server-side request forgery: the address is checked after DNS resolution, at connect time, so a hostname can't point at loopback, private, link-local or metadata addresses, and redirects are never followed. Private networks can be allowed explicitly for self-hosted setups (webhooks.allow_private_networks).

Index

Constants

This section is empty.

Variables

View Source
var ErrBlocked = errors.New("address not allowed")

ErrBlocked is returned when a URL resolves to a forbidden address.

Functions

func Describe

func Describe(ctx context.Context, err error) string

Describe turns a transport error into a short sentence for delivery logs.

func IsBlocked

func IsBlocked(err error) bool

IsBlocked reports whether err comes from the address policy.

Types

type Policy

type Policy struct {
	// AllowPrivate allows loopback and RFC 1918 addresses (self-hosted receivers).
	AllowPrivate bool
}

Policy decides which addresses may be dialed.

func (Policy) Check

func (p Policy) Check(ip netip.Addr) error

Check reports whether ip may be dialed.

func (Policy) Client

func (p Policy) Client(timeout time.Duration) *http.Client

Client returns an HTTP client that refuses forbidden addresses at connect time and never follows redirects.

func (Policy) Dialer

func (p Policy) Dialer(timeout time.Duration) *net.Dialer

Dialer returns a dialer that refuses forbidden addresses at connect time, for raw connections (SMTP, IMAP, POP3) and for Client.

func (Policy) ValidateURL

func (p Policy) ValidateURL(raw string) (*url.URL, error)

ValidateURL checks the scheme and host of a URL before it is stored. The address itself is checked again at every connection.

Jump to

Keyboard shortcuts

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