metadataurl

package
v1.261125.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 14 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 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 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(base http.RoundTripper) Checker

NewChecker returns the bounded HTTP checker built on base. A base *http.Transport is cloned, restricted to public destinations and bounded by the check limits; any other RoundTripper is used as given.

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