Documentation
¶
Overview ¶
Package utils provides internal utility functions used throughout the logger package.
This package contains helper functions for common tasks such as file path handling, security utilities, and I/O operations. These utilities are primarily for internal use by the logger package and are not intended to be part of the public API.
The utilities include path security functions to prevent directory traversal attacks when handling user-supplied file paths.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SecurePath ¶
SecurePath takes a relative path string and returns a secure absolute path within the system's temporary directory. This function helps prevent path traversal attacks and unauthorized file access.
The function performs several security checks, including: - Rejecting empty paths - Normalizing the path using filepath.Clean - Preventing directory traversal sequences (..) - Disallowing absolute paths (except those already within the system temp directory) - Verifying that any symlinks in the path don't escape the temporary directory
Parameters:
- path: The input path to secure, expected to be a relative path
Returns:
- A secured absolute path within the system's temporary directory
- An error if any security check fails or if the path is invalid
Note: This function is designed to be used before performing file operations where user-supplied paths need to be confined to a safe directory.
Types ¶
This section is empty.