Help us shape the future of Go! Take the 2026 Go Developer Survey

security

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccessDenied           = errors.New("access denied")
	ErrPathOutsideAllowed     = errors.New("path is outside allowed directories")
	ErrSymlinkOutside         = errors.New("symlink target is outside allowed directories")
	ErrSymlinkOperationDenied = errors.New("operation denied: path is a symlink")
	ErrNullByte               = errors.New("path contains null byte")
	ErrEmptyPath              = errors.New("path is empty")
	ErrNoValidAncestor        = errors.New("no valid ancestor found within allowed directories")
)

Sentinel errors for path validation.

Functions

func IsPathWithinAllowedDirectories

func IsPathWithinAllowedDirectories(path string, allowedDirs []string) bool

IsPathWithinAllowedDirectories checks if a path is within any of the allowed directories.

func ValidateFinalPath

func ValidateFinalPath(path string, allowedDirs []string) (string, error)

ValidateFinalPath validates an existing path and rejects symlinks. It returns the resolved absolute path if valid.

func ValidateFinalPathForCreation

func ValidateFinalPathForCreation(path string, allowedDirs []string) (string, error)

ValidateFinalPathForCreation validates a path for creation and rejects symlink destinations. It returns the resolved absolute path if valid.

func ValidateNoSymlinksInPath

func ValidateNoSymlinksInPath(path string, allowedDirs []string) error

ValidateNoSymlinksInPath walks each segment of the path starting from the allowed root and verifies that no component is a symlink. Returns nil if all components are regular directories (or don't exist). This prevents symlink TOCTOU attacks during directory creation or file operations.

func ValidatePath

func ValidatePath(path string, allowedDirs []string) (string, error)

ValidatePath validates that a path is within allowed directories and safe to access. It returns the resolved absolute path if valid.

func ValidatePathForCreation

func ValidatePathForCreation(path string, allowedDirs []string) (string, error)

ValidatePathForCreation validates a path for file/directory creation. It checks that the parent directory is within allowed directories.

func ValidatePathForCreationWithResolved

func ValidatePathForCreationWithResolved(path string, allowedDirs []string, resolvedAllowed []string) (string, error)

ValidatePathForCreationWithResolved validates a path for creation using pre-resolved allowed directories. This avoids redundant symlink resolution when the caller has already resolved them.

func ValidatePathWithResolved

func ValidatePathWithResolved(path string, allowedDirs []string, resolvedAllowed []string) (string, error)

ValidatePathWithResolved validates a path using pre-resolved allowed directories. This avoids redundant symlink resolution when the caller has already resolved them.

Types

This section is empty.

Jump to

Keyboard shortcuts

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