security

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPathTraversal  = errors.New("path contains directory traversal sequences")
	ErrAbsolutePath   = errors.New("absolute paths are not allowed")
	ErrEmptyPath      = errors.New("path cannot be empty")
	ErrInvalidPath    = errors.New("invalid path")
	ErrOutsideBaseDir = errors.New("path is outside allowed base directory")
)
View Source
var (
	ErrInvalidURL         = errors.New("invalid URL format")
	ErrInvalidScheme      = errors.New("URL scheme must be http or https")
	ErrPrivateIP          = errors.New("URL points to private/local IP address")
	ErrLinkLocal          = errors.New("URL points to a link-local address")
	ErrBlockedDomain      = errors.New("domain is in blocklist")
	ErrEmptyURL           = errors.New("URL cannot be empty")
	ErrIPResolutionFailed = errors.New("failed to resolve domain")
)
View Source
var ErrTooManyRedirects = errors.New("too many redirects")

Functions

func IsBlockedAddress added in v1.10.0

func IsBlockedAddress(err error) bool

IsBlockedAddress reports whether err comes from an address or domain the server refused to connect to, rather than from a network or server fault.

func NewHTTPClient added in v1.10.0

func NewHTTPClient() *http.Client

NewHTTPClient returns a client that validates every address it connects to. Callers set Timeout themselves. Validation at dial time covers each redirect hop and the address the connection actually reaches, which a check against the requested URL alone does not.

func SafeCreate

func SafeCreate(sp *SecurePath) (*os.File, error)

func SafeJoin

func SafeJoin(basePath, userPath string) (string, error)

func SafeMkdirAll

func SafeMkdirAll(sp *SecurePath, perm os.FileMode) error

func SafeOpen

func SafeOpen(sp *SecurePath) (*os.File, error)

func SafeReadFile added in v1.7.0

func SafeReadFile(sp *SecurePath) ([]byte, error)

func SafeRemove

func SafeRemove(sp *SecurePath) error

func SafeRemoveIfExists

func SafeRemoveIfExists(sp *SecurePath) error

func SafeRename

func SafeRename(oldpath, newpath *SecurePath) error

func SafeStat

func SafeStat(sp *SecurePath) (os.FileInfo, error)

func SafeStatExists

func SafeStatExists(sp *SecurePath) bool

func ValidateAndCleanFilename

func ValidateAndCleanFilename(filename string) (string, error)

func ValidateExistingFilePath

func ValidateExistingFilePath(path string) error

func ValidateFilePath

func ValidateFilePath(path string) error

func ValidateFilePathInBase

func ValidateFilePathInBase(path, baseDir string) error

func ValidateStorageKey

func ValidateStorageKey(key string) error

func ValidateURL

func ValidateURL(rawURL string) error

Types

type SecurePath

type SecurePath struct {
	// contains filtered or unexported fields
}

func NewSecurePath

func NewSecurePath(userPath string) (*SecurePath, error)

func NewSecurePathFromExisting

func NewSecurePathFromExisting(existingPath string) (*SecurePath, error)

func NewSecurePathInBase

func NewSecurePathInBase(userPath, baseDir string) (*SecurePath, error)

func NewSecureStorageKey

func NewSecureStorageKey(key string) (*SecurePath, error)

func (*SecurePath) Dir

func (sp *SecurePath) Dir() *SecurePath

func (*SecurePath) Join

func (sp *SecurePath) Join(elem string) (*SecurePath, error)

func (*SecurePath) String

func (sp *SecurePath) String() string

Jump to

Keyboard shortcuts

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