validate_path

Function validate_path 

Source
pub fn validate_path<P: AsRef<Path>>(path: P) -> Result<PathBuf>
Expand description

Validates a path for basic security constraints

This function performs essential security checks:

  • Canonicalizes the path to resolve symlinks and relative components
  • Prevents path traversal attacks by checking for “..” patterns
  • Validates that the path is within reasonable bounds

§Examples

use turbomcp_protocol::security::validate_path;

// Safe path
let safe_path = validate_path("/home/user/data.txt")?;

// Path traversal attempt - will fail
let result = validate_path("/home/user/../../../etc/passwd");
assert!(result.is_err());