Skip to main content

file_path

Function file_path 

Source
pub fn file_path() -> Sanitizer<FilePath>
Expand description

Sanitizer for relative file paths.

Use for upload destinations, template includes, plugin paths, or any path that must stay within a base directory. Rejects absolute paths and .. traversal.

§Rules

§Example

use shell_sanitize_rules::presets;

let s = presets::file_path();

// Relative path within allowed directory
assert!(s.sanitize("uploads/photo.jpg").is_ok());

// Traversal attack
assert!(s.sanitize("../../etc/passwd").is_err());

// Absolute path escape
assert!(s.sanitize("/etc/shadow").is_err());