netguard

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package netguard restricts the network destinations the cloud-backup subsystem is allowed to connect to (SSRF mitigation). The guard is applied as a net.Dialer Control hook, which runs against the concrete IP that will actually be dialed, after DNS resolution.

Index

Constants

View Source
const AllowPrivateNetworksEnv = "BACKUP_ALLOW_PRIVATE_NETWORKS"

AllowPrivateNetworksEnv, when set to "true", permits connections to RFC-1918 / unique-local / CGNAT ranges. Loopback, link-local, unspecified, and multicast addresses are always blocked regardless of this setting.

Variables

This section is empty.

Functions

This section is empty.

Types

type Guard

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

Guard decides whether a connection to a resolved IP is permitted.

func FromEnv

func FromEnv() *Guard

FromEnv builds a Guard from AllowPrivateNetworksEnv. Private networks are blocked unless the variable is explicitly set to "true".

func New

func New(allowPrivate bool) *Guard

New returns a Guard. When allowPrivate is true, private/ULA/CGNAT ranges are permitted (loopback, link-local, unspecified, and multicast are always blocked).

func (*Guard) Allowed

func (g *Guard) Allowed(ip net.IP) bool

Allowed reports whether a connection to ip is permitted.

func (*Guard) Control

func (g *Guard) Control(network, address string, _ syscall.RawConn) error

Control is a net.Dialer Control hook. It rejects the connection if the resolved address is a blocked destination. address is "ip:port".

func (*Guard) DialContext

func (g *Guard) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

DialContext is a guarded dial function suitable for SFTP and any other caller that dials directly.

func (*Guard) Dialer

func (g *Guard) Dialer(timeout time.Duration) *net.Dialer

Dialer returns a net.Dialer whose Control hook enforces the guard.

func (*Guard) HTTPClient

func (g *Guard) HTTPClient(timeout time.Duration) *http.Client

HTTPClient returns an *http.Client using a guarded transport and the given overall timeout.

func (*Guard) HTTPTransport

func (g *Guard) HTTPTransport() *http.Transport

HTTPTransport returns an *http.Transport whose connections are guarded. It is used by the S3 and WebDAV providers.

Jump to

Keyboard shortcuts

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