pub struct PathValidator;Expand description
Validates paths against security threats
Implementations§
Source§impl PathValidator
impl PathValidator
Sourcepub fn contains_null_bytes(path: &str) -> bool
pub fn contains_null_bytes(path: &str) -> bool
Layer 1: Check for null bytes
Sourcepub fn contains_path_traversal(path: &str) -> bool
pub fn contains_path_traversal(path: &str) -> bool
Layer 2: Check for path traversal components (../)
Sourcepub fn contains_url_encoded_traversal(path: &str) -> bool
pub fn contains_url_encoded_traversal(path: &str) -> bool
Layer 3: Check for URL-encoded traversal
Sourcepub fn starts_with_tilde(path: &str) -> bool
pub fn starts_with_tilde(path: &str) -> bool
Layer 4: Check for tilde expansion (~user)
Sourcepub fn is_absolute(path: &str) -> bool
pub fn is_absolute(path: &str) -> bool
Layer 5: Check if path is absolute
Sourcepub fn matches_forbidden_prefix(
path: &str,
forbidden: &[String],
) -> Option<String>
pub fn matches_forbidden_prefix( path: &str, forbidden: &[String], ) -> Option<String>
Layer 6: Check against forbidden path prefixes
Sourcepub fn normalize_path(path: &str) -> String
pub fn normalize_path(path: &str) -> String
Normalize a path for comparison
Sourcepub fn is_within_allowed_roots(
resolved: &Path,
allowed_roots: &[PathBuf],
) -> bool
pub fn is_within_allowed_roots( resolved: &Path, allowed_roots: &[PathBuf], ) -> bool
Check if a resolved path is within allowed roots
Sourcepub async fn validate_no_symlink_escape(
path: &Path,
workspace: &Path,
) -> Result<(), String>
pub async fn validate_no_symlink_escape( path: &Path, workspace: &Path, ) -> Result<(), String>
Validate that a path doesn’t escape the workspace via symlinks
Sourcepub fn get_extension(path: &str) -> Option<String>
pub fn get_extension(path: &str) -> Option<String>
Get the file extension from a path
Sourcepub fn is_extension_forbidden(ext: &str, forbidden: &[String]) -> bool
pub fn is_extension_forbidden(ext: &str, forbidden: &[String]) -> bool
Check if an extension is in the forbidden list
Sourcepub fn sanitize_component(component: &str) -> String
pub fn sanitize_component(component: &str) -> String
Sanitize a path component for safe use
Auto 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
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