Documentation
¶
Overview ¶
Package pathutil provides path manipulation utilities for the server package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPath is returned when the resolved file path cannot be made absolute. ErrInvalidPath = errors.New("invalid file path") // ErrInvalidImagesDir is returned when the images directory path cannot be made absolute. ErrInvalidImagesDir = errors.New("invalid images directory") // ErrPathTraversal is returned when the file path escapes the images directory. ErrPathTraversal = errors.New("path traversal detected") )
Sentinel errors returned by SafeImagePath.
Functions ¶
func RemoveImagesDirPrefix ¶
RemoveImagesDirPrefix removes images dir prefix with path traversal check. normalizedImagesDir should be the pre-normalized result of filepath.ToSlash(imagesDir). Returns an error if the resulting path contains path traversal sequences (..) or if an absolute path lies outside the images directory.
func SafeImagePath ¶ added in v0.7.0
SafeImagePath resolves a file path within the images directory and ensures it does not escape the images root via "../" path traversal. It returns the absolute safe path or one of the sentinel errors ErrInvalidPath, ErrInvalidImagesDir, or ErrPathTraversal.
The check is simple: filepath.Join normalizes "../" components, so comparing the joined absolute path against the images directory prefix catches any traversal attempt. Symlinks inside the images directory are not resolved — the OS kernel handles them transparently when the path is used for serving.
Types ¶
This section is empty.