httpsafe

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: GPL-3.0 Imports: 6 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 httpsafe provides SSRF-safe HTTP helpers for the adapters. It centralises the host-allowlist check and a CheckRedirect hook so every crawl client applies the same policy.

Index

Constants

This section is empty.

Variables

View Source
var LookupHostIPs = func(ctx context.Context, host string) ([]net.IP, error) {
	addrs, err := net.DefaultResolver.LookupIPAddr(ctx, host)
	if err != nil {
		return nil, err
	}
	out := make([]net.IP, len(addrs))
	for i, a := range addrs {
		out[i] = a.IP
	}
	return out, nil
}

LookupHostIPs is overridable for tests. Production calls resolve via net.DefaultResolver.

Functions

func AllowedHost

func AllowedHost(ctx context.Context, u *url.URL) bool

AllowedHost reports whether u's host is safe to connect to. Hostnames are resolved and every returned IP is checked against the blocklist (loopback, link-local, RFC1918, carrier-grade NAT, cloud-metadata ranges, IPv6 unique-local). Unresolvable hosts fail closed.

func BlockedIP

func BlockedIP(ip net.IP) bool

BlockedIP reports whether ip belongs to a range the crawler must not contact (loopback, link-local, RFC1918, CGNAT, cloud-metadata, IPv6 unique-local or link-local).

func CheckRedirect

func CheckRedirect(req *http.Request, via []*http.Request) error

CheckRedirect is an http.Client.CheckRedirect hook that aborts the chain when the next target resolves to a blocked host, and caps the hop count at 10.

Types

This section is empty.

Jump to

Keyboard shortcuts

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