safefetch

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 10 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 safefetch validates and downloads external media URLs with SSRF protection.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProhibitedScheme = errors.New("only https and data schemes are allowed")
	ErrProhibitedIP     = errors.New("prohibited IP address")
	ErrUnsupportedMIME  = errors.New("unsupported media MIME type")
	ErrPayloadTooLarge  = errors.New("media payload exceeds size limit")
)

Functions

func FetchURL

func FetchURL(ctx context.Context, rawURL string, maxBytes int64) ([]byte, string, error)

FetchURL downloads external media over HTTPS, enforcing SSRF IP blocking and payload limits.

func IsProhibitedIP

func IsProhibitedIP(ip net.IP) bool

IsProhibitedIP reports whether ip is a loopback, private, link-local, or cloud-metadata address.

func ParseDataURI

func ParseDataURI(uri string) (string, []byte, error)

ParseDataURI decodes a data URI into its MIME type and payload bytes.

func ValidateMediaMimeType

func ValidateMediaMimeType(mime string) error

ValidateMediaMimeType verifies that the MIME type corresponds to supported image, audio, or document formats.

Types

This section is empty.

Jump to

Keyboard shortcuts

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