pub fn validate_safe_path(path: &str) -> Result<String>
Expand description
Validate and sanitize file paths to prevent path traversal attacks
This function checks for common path traversal patterns and returns an error if any are detected. It also normalizes the path to prevent bypass attempts.
§Security Concerns
- Blocks
..
(parent directory) - Blocks
~
(home directory expansion) - Blocks absolute paths (starting with
/
or drive letters on Windows) - Blocks null bytes
§Example
use mockforge_core::validation::validate_safe_path;
assert!(validate_safe_path("data/file.txt").is_ok());
assert!(validate_safe_path("../etc/passwd").is_err());
assert!(validate_safe_path("/etc/passwd").is_err());