pub struct AllowedPathResolver { /* private fields */ }Expand description
Path resolver that restricts access to allowed directories.
Paths are resolved relative to configured base directories. Prevents path traversal attacks by validating resolved paths stay within allowed boundaries.
§Security
This resolver protects against path traversal by:
- Canonicalizing the resolved path to eliminate
..and symlinks - Verifying the result starts with an allowed base directory
§Bash Tool Bypasses Path Restrictions
When the bash/shell tool is enabled, this resolver’s protections are effectively
advisory. The bash tool permits arbitrary shell commands, meaning an LLM can
directly read, write, or delete any file the process has OS-level permissions for
(e.g., cat /etc/passwd, rm -rf /, curl ... | sh).
This resolver only restricts the structured file operations (read, write, edit,
glob, grep). If your threat model requires actual filesystem sandboxing, you must
either:
- Disable the bash tool entirely, or
- Run the process in an OS-level sandbox (containers, seccomp, landlock, etc.)
Implementations§
Source§impl AllowedPathResolver
impl AllowedPathResolver
Sourcepub fn new(
allowed_paths: impl IntoIterator<Item = impl AsRef<Path>>,
) -> ToolResult<Self>
pub fn new( allowed_paths: impl IntoIterator<Item = impl AsRef<Path>>, ) -> ToolResult<Self>
Creates a new resolver with the given allowed directories.
Each directory is canonicalized during construction to ensure consistent path comparison. Returns an error if any directory doesn’t exist or can’t be canonicalized.
Sourcepub fn from_canonical(
allowed_paths: impl IntoIterator<Item = impl AsRef<Path>>,
) -> Self
pub fn from_canonical( allowed_paths: impl IntoIterator<Item = impl AsRef<Path>>, ) -> Self
Creates a resolver from already-canonicalized paths.
Use this when paths are known to be valid and canonicalized, skipping the filesystem check.
§Safety
Caller must ensure paths are actually canonical. Using non-canonical paths may allow path traversal attacks.
Sourcepub fn allowed_paths(&self) -> &[PathBuf]
pub fn allowed_paths(&self) -> &[PathBuf]
Returns the allowed base directories.
Trait Implementations§
Source§impl Clone for AllowedPathResolver
impl Clone for AllowedPathResolver
Source§fn clone(&self) -> AllowedPathResolver
fn clone(&self) -> AllowedPathResolver
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more