security

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: AGPL-3.0 Imports: 8 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")
	ErrBlockedDomain      = errors.New("domain is in blocklist")
	ErrEmptyURL           = errors.New("URL cannot be empty")
	ErrIPResolutionFailed = errors.New("failed to resolve domain")
)

Functions

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