Skip to main content

validate_file_path

Function validate_file_path 

Source
pub fn validate_file_path(path: &str) -> Result<PathBuf>
Expand description

Validates a file path to prevent directory traversal attacks

§Security Checks

  • Rejects absolute paths
  • Rejects paths with .. components
  • Ensures path stays within current working directory
  • Normalizes and canonicalizes the path

§Arguments

  • path - User-provided file path

§Returns

  • Ok(PathBuf) if path is valid and safe
  • Err(io::Error) if path violates security constraints