ssrf

package
v0.0.0-...-ef789dd Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLookupIP

func DefaultLookupIP(ctx context.Context, host string) ([]net.IP, error)

DefaultLookupIP uses the system resolver.

func FilterAllowedIPs

func FilterAllowedIPs(ips []net.IP) ([]net.IP, error)

FilterAllowedIPs returns only public IPs. If any resolved address is blocked, or none remain, it returns an error (strict: mixed A/AAAA sets are rejected).

func IsBlockedIP

func IsBlockedIP(ip net.IP) bool

IsBlockedIP reports whether ip is unsuitable for outbound webhook destinations (loopback, RFC1918, link-local, ULA, unspecified, multicast, IANA special-purpose IPv4 including CGNAT/TEST-NET/benchmarking/reserved, NAT64).

func NewHTTPClient

func NewHTTPClient(timeout time.Duration, lookup LookupIPFunc) *http.Client

NewHTTPClient builds an http.Client that dials only SSRF-safe addresses. Redirects are disabled. Environment HTTP(S)_PROXY is ignored (egress proxy is out of scope — honoring it would skip destination IP checks).

Uses a dedicated Transport (not a Clone of http.DefaultTransport) so inherited DialTLS / DialTLSContext hooks cannot bypass SafeDialContext.

func SafeDialContext

func SafeDialContext(lookup LookupIPFunc) func(ctx context.Context, network, addr string) (net.Conn, error)

SafeDialContext returns a DialContext that resolves via lookup, rejects any blocked address, and connects only to an allowed IP (DNS-rebinding safe).

func ValidateURL

func ValidateURL(raw string) error

ValidateURL checks scheme/host and rejects literal / non-canonical blocked IPs. Hostnames are not resolved here — callers that dial must use SafeDialContext.

Types

type LookupIPFunc

type LookupIPFunc func(ctx context.Context, host string) ([]net.IP, error)

LookupIPFunc resolves a hostname to IP addresses (injectable for tests).

Jump to

Keyboard shortcuts

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