security

package
v0.5.0-pre14 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeFilename

func SanitizeFilename(s string) string

SanitizeFilename makes a safe filename from an arbitrary string. It replaces any characters that are not ASCII letters, digits, dot, underscore or dash with an underscore. It also collapses repeated underscores and trims the result to a reasonable length. This is intended for use when embedding user-provided identifiers into file names.

func ValidateExportPath

func ValidateExportPath(filePath string) error

ValidateExportPath validates a file path for export operations. It ensures the path is within either the temp directory or current working directory.

func ValidateOutputPath

func ValidateOutputPath(filePath string) error

ValidateOutputPath validates a file path for CLI output operations. It ensures the path is within the current working directory or temp directory, and doesn't attempt path traversal. This is intended for use with CLI tools that accept output file paths as arguments.

func ValidatePathWithinAllowedDirs

func ValidatePathWithinAllowedDirs(filePath string, allowedDirs []string) error

ValidatePathWithinAllowedDirs checks if a file path is within any of the allowed directories. Returns nil if the path is valid, or an error describing why it was rejected.

func ValidatePathWithinDirectory

func ValidatePathWithinDirectory(filePath, safeDir string) error

ValidatePathWithinDirectory checks if a file path is within a safe directory. It prevents path traversal attacks by ensuring the resolved path doesn't escape the specified safe directory. This includes protection against symlink-based attacks.

Types

This section is empty.

Jump to

Keyboard shortcuts

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