metadataurl

package
v1.260907.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package metadataurl provides bounded, read-only checks for public metadata URL destinations.

Index

Constants

View Source
const (
	// CheckConcurrency bounds simultaneous destination requests.
	CheckConcurrency = 4
	// CheckTimeout bounds each destination request when no ASC timeout override
	// is configured.
	CheckTimeout = 10 * time.Second
	// MaxRedirects bounds the number of HTTP(S) redirects followed.
	MaxRedirects = 10
)

Variables

View Source
var ErrUnsafeTarget = errors.New("metadata URL target is not a public internet address")

ErrUnsafeTarget reports a destination that is not safe to contact as a public metadata URL.

Functions

func CheckAll

func CheckAll(ctx context.Context, checker Checker, rawURLs []string) (map[string]Outcome, error)

CheckAll checks each unique, trimmed URL once, with bounded concurrency. The returned map is keyed by the trimmed URL supplied to the checker. An individual request failure is retained in Outcome and does not abort the remaining checks. Context cancellation is returned to the caller.

func IsHTTPURL

func IsHTTPURL(parsed *url.URL) bool

IsHTTPURL reports whether parsed is an absolute HTTP(S) URL with a host.

func IsPublicIP

func IsPublicIP(address netip.Addr) bool

IsPublicIP reports whether address is suitable for an outbound metadata destination.

func NewHTTPClient

func NewHTTPClient() *http.Client

NewHTTPClient returns the configured bounded HTTP client. It is exported for compatibility adapters and tests that need to inject a custom transport.

func PublicDialControl

func PublicDialControl(_ context.Context, _, address string, _ syscall.RawConn) error

PublicDialControl rejects every resolved non-public address, including addresses that otherwise look global-unicast but belong to special-purpose IANA ranges.

func RedirectPolicy

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

RedirectPolicy rejects non-HTTP(S), userinfo, unsafe literal IP, and excessive redirects. DNS-resolved destinations are checked again by PublicDialControl.

Types

type Checker

type Checker interface {
	Check(context.Context, string) (Result, error)
}

Checker checks one HTTP(S) destination.

func NewChecker

func NewChecker() Checker

NewChecker returns the production bounded HTTP checker.

type Outcome

type Outcome struct {
	Result Result
	Err    error
}

Outcome is the result of checking one destination.

type Result

type Result struct {
	FinalURL       *url.URL
	StatusCode     int
	RedirectedHost bool
}

Result contains the response metadata needed by callers. Response bodies are never retained.

func CheckWithClient

func CheckWithClient(ctx context.Context, client *http.Client, rawURL string) (Result, error)

CheckWithClient performs one bounded request using client. It is useful for package adapters that need a custom RoundTripper while retaining the shared request contract.

Jump to

Keyboard shortcuts

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