Skip to main content

PathAllowList

Struct PathAllowList 

Source
pub struct PathAllowList { /* private fields */ }
Expand description

Denies a call whose path-valued arguments fall outside a set of allowed roots.

Checks the named arguments when present, and requires each to be an absolute path contained by one of the allowed roots. Containment is compared by path component and after resolving the allowed root and every existing candidate component, so string-prefix, dangling-symlink, and resolved-symlink escapes are refused. Any path containing a .. component is denied outright.

This is a preflight policy check, not a replacement for opening filesystem paths relative to a trusted directory handle. A hostile process able to replace path components between validation and tool execution can create a time-of-check/time-of-use race; filesystem tools operating across such a trust boundary must still use platform secure-open primitives.

§Example

use adk_guardrail::PathAllowList;

let guardrail = PathAllowList::new(
    "launch-agents-only",
    ["path"],
    ["/Users/me/Library/LaunchAgents"],
);

Implementations§

Source§

impl PathAllowList

Source

pub fn new<A, S, R, P>( name: impl Into<String>, arg_names: A, allowed_roots: R, ) -> Self
where A: IntoIterator<Item = S>, S: Into<String>, R: IntoIterator<Item = P>, P: Into<PathBuf>,

Creates a guardrail confining arg_names to allowed_roots.

Source

pub fn with_severity(self, severity: Severity) -> Self

Sets the severity reported on denial. Defaults to Severity::Critical.

Source

pub fn on_tools<I, S>(self, tools: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Restricts this guardrail to the named tools. Without this it applies to every tool.

Trait Implementations§

Source§

impl ToolGuardrail for PathAllowList

Source§

fn name(&self) -> &str

Unique name, used in denial messages and logs.
Source§

fn applies_to(&self, tool_name: &str) -> bool

Whether this guardrail applies to tool_name. Defaults to every tool. Read more
Source§

fn validate_call<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tool_name: &'life1 str, args: &'life2 Value, ) -> Pin<Box<dyn Future<Output = ToolGuardrailResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Validates a call to tool_name with args.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more