pub struct PathGuard { /* private fields */ }Expand description
Workspace path guard with cached canonical root.
Validates that paths stay within the workspace directory after symlink resolution. Two-layer defense:
- Syntactic check (no I/O): rejects
../traversal beyond root - Symlink-aware check: canonicalizes and verifies containment
Implementations§
Source§impl PathGuard
impl PathGuard
Sourcepub fn new(
root: PathBuf,
absolute_policy: AbsolutePathPolicy,
) -> Result<Self, ContainmentError>
pub fn new( root: PathBuf, absolute_policy: AbsolutePathPolicy, ) -> Result<Self, ContainmentError>
Create a new path guard rooted at root.
Canonicalizes root once at construction time.
Returns an error if root cannot be canonicalized.
Sourcepub fn check_path(&self, path: &str) -> Result<PathBuf, ContainmentError>
pub fn check_path(&self, path: &str) -> Result<PathBuf, ContainmentError>
Validate that path stays within the workspace root (or additional roots if configured).
Returns the canonicalized path on success. Rejects paths that
escape the allowed roots via ../ traversal or symlinks.
Sourcepub fn canon_root(&self) -> &Path
pub fn canon_root(&self) -> &Path
The canonicalized workspace root.
Sourcepub fn would_allow(&self, path: &str) -> bool
pub fn would_allow(&self, path: &str) -> bool
Returns true if the path would be allowed under the current policy (dry-run, no error details).
Source§impl PathGuard
impl PathGuard
Sourcepub fn builder(root: PathBuf) -> PathGuardBuilder
pub fn builder(root: PathBuf) -> PathGuardBuilder
Create a builder for ergonomic configuration of allowed roots.
Sourcepub fn new_with_policy(
root: PathBuf,
policy: AbsolutePathPolicy,
) -> Result<Self, ContainmentError>
pub fn new_with_policy( root: PathBuf, policy: AbsolutePathPolicy, ) -> Result<Self, ContainmentError>
Create with explicit policy (back-compat + power users).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PathGuard
impl RefUnwindSafe for PathGuard
impl Send for PathGuard
impl Sync for PathGuard
impl Unpin for PathGuard
impl UnsafeUnpin for PathGuard
impl UnwindSafe for PathGuard
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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