pub struct PathValidator { /* private fields */ }Expand description
Validates paths for security-critical file operations
Prevents common attack vectors:
- Path traversal (../)
- Symlink escapes
- Null byte injection
- Unicode normalization attacks
- Absolute path escapes
- Depth limit violations
Implementations§
Source§impl PathValidator
impl PathValidator
Sourcepub fn new(workspace_root: &Path) -> Self
pub fn new(workspace_root: &Path) -> Self
Create a new validator with workspace root
§Example
use crate::utils::path_validator::PathValidator;
use std::path::Path;
let validator = PathValidator::new(Path::new("/workspace"));Sourcepub fn with_max_depth(self, max_depth: usize) -> Self
pub fn with_max_depth(self, max_depth: usize) -> Self
Set maximum path depth
Sourcepub fn with_allowed_extensions(self, extensions: Vec<&str>) -> Self
pub fn with_allowed_extensions(self, extensions: Vec<&str>) -> Self
Set allowed file extensions
Sourcepub fn with_absolute_paths(self, allow: bool) -> Self
pub fn with_absolute_paths(self, allow: bool) -> Self
Allow absolute paths
Sourcepub fn with_follow_symlinks(self, follow: bool) -> Self
pub fn with_follow_symlinks(self, follow: bool) -> Self
Set whether to follow symlinks
Sourcepub fn validate(&self, path: impl AsRef<Path>) -> Result<SafePath>
pub fn validate(&self, path: impl AsRef<Path>) -> Result<SafePath>
Validate a path and return a SafePath
§Errors
Returns error if path:
- Contains null bytes
- Contains “..” components
- Is absolute (unless allowed)
- Exceeds max depth
- Has invalid extension
- Escapes workspace
- Is a symlink pointing outside workspace
Trait Implementations§
Source§impl Clone for PathValidator
impl Clone for PathValidator
Source§fn clone(&self) -> PathValidator
fn clone(&self) -> PathValidator
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PathValidator
impl RefUnwindSafe for PathValidator
impl Send for PathValidator
impl Sync for PathValidator
impl Unpin for PathValidator
impl UnsafeUnpin for PathValidator
impl UnwindSafe for PathValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> EvidenceKind for T
impl<T> EvidenceKind for T
default fn kind_label(&self) -> &'static str
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more