netguard

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 9 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 netguard keeps outbound calls to URLs that instance admins configure — webhooks, custom OAuth/OIDC providers, SAML metadata, privacy destinations — off the server's own network, and parses the network lists (trusted proxies, allowed networks) the operator configures.

The check runs on the address actually dialled, after DNS resolution, so a name that resolves to a public address when saved and an internal one later (DNS rebinding), or a redirect to an internal URL, is refused too.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotPublic = errors.New("address is not public")

ErrNotPublic is what a guarded dial fails with for an address outside the public internet and outside the allowed networks.

Functions

func Allowed

func Allowed(addr netip.Addr, allow Networks) bool

Allowed reports whether a guarded call may reach addr: a public address, or one in allow.

func CheckHost

func CheckHost(ctx context.Context, host string, allow Networks) error

CheckHost resolves host, when a URL is saved, so an admin learns straight away that it points inside the network. The dial-time check is the one that holds.

func ClientIP

func ClientIP(remoteAddr string, xff []string, trusted Networks) string

ClientIP is the address of the caller of a request that reached the server from remoteAddr carrying the X-Forwarded-For header lines xff, in the order they arrived. A proxy may append its hop as a line of its own rather than to the existing value (HAProxy's option forwardfor), so every line counts: read alone, the first line is whatever the client wrote.

X-Forwarded-For is written by whoever sends the request, so it is believed only as far as proxies the operator trusts vouch for it: when the peer is a trusted proxy, the header is read from the right, skipping trusted proxies, and the first address that is not one is the client. An untrusted peer is the client itself, whatever the header says. With trusted = "*" every hop is trusted and the leftmost address is the client (the previous behaviour, and upstream's).

func Control

func Control(allow Networks) func(string, string, syscall.RawConn) error

Control is a net.Dialer Control that refuses addresses Allowed rejects.

func IsPublic

func IsPublic(addr netip.Addr) bool

IsPublic reports whether addr is on the public internet.

func Transport

func Transport(base http.RoundTripper, allow Networks) *http.Transport

Transport returns a copy of base whose dials are guarded. It ignores HTTP_PROXY: through a proxy the dialled address would be the proxy's. A base that is not an *http.Transport is replaced by a default one.

Types

type Networks

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

Networks is a set of addresses given as a comma-separated list of IPs and CIDRs, or "*" for every address. The zero value contains nothing.

func MustParseNetworks

func MustParseNetworks(spec string) Networks

MustParseNetworks is ParseNetworks for constants.

func ParseNetworks

func ParseNetworks(spec string) (Networks, error)

ParseNetworks parses "10.0.0.0/8, 192.168.1.5, ::1" or "*". Blank is empty.

func (Networks) Contains

func (n Networks) Contains(addr netip.Addr) bool

Contains reports whether addr is in the set.

func (Networks) Empty

func (n Networks) Empty() bool

Empty reports whether the set contains nothing.

Jump to

Keyboard shortcuts

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