pub struct PathLattice {
pub allowed: HashSet<String>,
pub blocked: HashSet<String>,
pub work_dir: Option<PathBuf>,
}Expand description
Path access lattice with allowed/blocked semantics.
allowed: Glob patterns for allowed paths. Empty means “all allowed”.blocked: Glob patterns for blocked paths. Checked first (takes priority).work_dir: Optional sandbox root. All paths are resolved relative to this.
§Security
- All paths are canonicalized to prevent
../../../.envtraversal attacks - Symlinks are resolved and checked against the work_dir sandbox
- Paths outside the work_dir are blocked when sandbox is enabled
Fields§
§allowed: HashSet<String>Allowed paths (glob patterns). Empty means “all allowed”.
blocked: HashSet<String>Blocked paths (glob patterns). Union in meet operation.
work_dir: Option<PathBuf>Optional sandbox root directory. When set, all paths must be within this directory.
Implementations§
Source§impl PathLattice
impl PathLattice
Sourcepub fn with_work_dir(work_dir: impl Into<PathBuf>) -> Self
pub fn with_work_dir(work_dir: impl Into<PathBuf>) -> Self
Create a new path lattice with a sandbox root directory.
All path operations will be constrained to this directory.
Sourcepub fn meet(&self, other: &Self) -> Self
pub fn meet(&self, other: &Self) -> Self
Meet operation: intersection of allowed, union of blocked.
The work_dir is taken from the first lattice if set, otherwise from the second. If both have work_dirs, the more restrictive (shorter prefix) is used.
Sourcepub fn join(&self, other: &Self) -> Self
pub fn join(&self, other: &Self) -> Self
Join operation: union of allowed, intersection of blocked.
Sourcepub fn can_access(&self, path: &Path) -> bool
pub fn can_access(&self, path: &Path) -> bool
Check if a path is accessible according to this lattice.
§Security
This method:
- Canonicalizes the path to prevent traversal attacks
- Checks if the path is within the sandbox (if work_dir is set)
- Checks blocked patterns (takes priority)
- Checks allowed patterns (if any are set)
Sourcepub fn leq(&self, other: &Self) -> bool
pub fn leq(&self, other: &Self) -> bool
Check if this lattice is less than or equal to another.
Sourcepub fn block_sensitive() -> Self
pub fn block_sensitive() -> Self
Create a path lattice that blocks sensitive files.
Sourcepub fn sandboxed_sensitive(work_dir: impl Into<PathBuf>) -> Self
pub fn sandboxed_sensitive(work_dir: impl Into<PathBuf>) -> Self
Create a path lattice that blocks sensitive files and sandboxes to a directory.
Trait Implementations§
Source§impl Clone for PathLattice
impl Clone for PathLattice
Source§fn clone(&self) -> PathLattice
fn clone(&self) -> PathLattice
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more