switchyard/fs/paths.rs
1//! Path utilities for Switchyard filesystem operations.
2
3use std::path::Path;
4
5/// Validate path to prevent directory traversal attacks.
6/// This is a conservative check used before performing mutations.
7#[must_use]
8pub fn is_safe_path(path: &Path) -> bool {
9 for component in path.components() {
10 if let std::path::Component::ParentDir = component {
11 return false;
12 }
13 }
14 if let Some(path_str) = path.to_str() {
15 if path_str.contains("/../") || path_str.contains("..\\") {
16 return false;
17 }
18 }
19 true
20}