safety

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBodyTooLarge = errors.New("response body too large")

ErrBodyTooLarge indicates a response body exceeded the configured read limit.

Functions

func CleanRelativePath

func CleanRelativePath(p string) (string, error)

CleanRelativePath validates and normalizes a relative path. It rejects absolute paths and parent traversal segments.

func EnsureUnderRoot

func EnsureUnderRoot(root, candidate string) (string, error)

EnsureUnderRoot verifies candidate resolves under root and returns an absolute normalized path.

func IsLoopbackHost

func IsLoopbackHost(u *url.URL) bool

IsLoopbackHost reports whether the URL host is localhost/loopback.

func NewHTTPClient

func NewHTTPClient(timeout time.Duration) *http.Client

NewHTTPClient creates a hardened HTTP client suitable for untrusted upstream content.

func ReadAllWithLimit

func ReadAllWithLimit(r io.Reader, limit int64) ([]byte, error)

ReadAllWithLimit reads from r and fails if content exceeds limit bytes.

func SafeJoinUnder

func SafeJoinUnder(root, rel string) (string, error)

SafeJoinUnder joins a validated relative path under root and verifies the final path remains inside root.

func ValidateHTTPURL

func ValidateHTTPURL(raw string) (*url.URL, error)

ValidateHTTPURL ensures the URL parses as HTTP(S) and contains no userinfo.

Types

This section is empty.

Jump to

Keyboard shortcuts

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