Skip to main content

validate_path

Function validate_path 

Source
pub fn validate_path(
    path_str: &str,
    base_dir: Option<&Path>,
    is_write: bool,
) -> Result<PathBuf>
Expand description

Validate a file path for security.

Checks performed:

  1. Path length must not exceed MAX_PATH_LENGTH
  2. No path traversal patterns (..)
  3. Path must be within project base directory (if specified)
  4. Cannot write to critical system files (if writing)

§Arguments

  • path_str - User-provided path string
  • base_dir - Project base directory (optional)
  • is_write - Whether this is a write operation (more strict)

§Returns

  • Ok(PathBuf) - Validated canonical path
  • Err(...) - Validation failure with descriptive error