Skip to main content

CompiledContextCondition

Enum CompiledContextCondition 

Source
pub enum CompiledContextCondition {
Show 22 variants TimeWindow { start_hour: u8, end_hour: u8, days: Vec<u8>, deny_reason: String, }, MaxCalls { tool_pattern: PatternMatcher, max: u64, deny_reason: String, }, AgentId { allowed: Vec<String>, blocked: Vec<String>, deny_reason: String, }, RequirePreviousAction { required_tool: String, deny_reason: String, }, ForbiddenPreviousAction { forbidden_tool: String, deny_reason: String, }, MaxCallsInWindow { tool_pattern: PatternMatcher, max: u64, window: usize, deny_reason: String, }, MaxChainDepth { max_depth: usize, deny_reason: String, }, AgentIdentityMatch { required_issuer: Option<String>, required_subject: Option<String>, required_audience: Option<String>, required_claims: HashMap<String, String>, blocked_issuers: Vec<String>, blocked_subjects: Vec<String>, require_attestation: bool, deny_reason: String, }, AsyncTaskPolicy { max_concurrent: usize, max_duration_secs: u64, require_self_cancel: bool, deny_reason: String, }, ResourceIndicator { allowed_resources: Vec<PatternMatcher>, require_resource: bool, deny_reason: String, }, CapabilityRequired { required_capabilities: Vec<String>, blocked_capabilities: Vec<String>, deny_reason: String, }, StepUpAuth { required_level: u8, deny_reason: String, }, CircuitBreaker { tool_pattern: PatternMatcher, deny_reason: String, }, DeputyValidation { require_principal: bool, max_delegation_depth: u8, deny_reason: String, }, ShadowAgentCheck { require_known_fingerprint: bool, min_trust_level: u8, deny_reason: String, }, SchemaPoisoningCheck { mutation_threshold: f32, deny_reason: String, }, MinVerificationTier { required_tier: u8, deny_reason: String, }, RequireCapabilityToken { required_issuers: Vec<String>, min_remaining_depth: u8, deny_reason: String, }, SessionStateRequired { allowed_states: Vec<String>, deny_reason: String, }, RequiredActionSequence { sequence: Vec<String>, ordered: bool, deny_reason: String, }, ForbiddenActionSequence { sequence: Vec<String>, ordered: bool, deny_reason: String, }, WorkflowTemplate { adjacency: HashMap<String, Vec<String>>, governed_tools: HashSet<String>, entry_points: Vec<String>, strict: bool, deny_reason: String, },
}
Expand description

A pre-compiled context condition for session-level policy evaluation.

Context conditions are checked after tool match and path/network rules, but before policy type dispatch. They require an vellaveto_types::EvaluationContext to evaluate — when no context is provided, all context conditions are skipped.

Variants§

§

TimeWindow

Allow tool calls only within a time window.

Fields

§start_hour: u8
§end_hour: u8
§days: Vec<u8>

ISO weekday numbers (1=Mon, 7=Sun). Empty = all days.

§deny_reason: String
§

MaxCalls

Limit how many times a tool (or tool pattern) can be called per session.

Fields

§tool_pattern: PatternMatcher
§max: u64
§deny_reason: String
§

AgentId

Restrict which agent identities can use this policy.

Fields

§allowed: Vec<String>
§blocked: Vec<String>
§deny_reason: String
§

RequirePreviousAction

Require that a specific tool was called earlier in the session.

Fields

§required_tool: String
§deny_reason: String
§

ForbiddenPreviousAction

Deny if a specific tool was called earlier in the session.

Inverse of RequirePreviousAction — detects forbidden sequences like read-then-exfiltrate (if read_file was called, deny http_request).

Fields

§forbidden_tool: String

Tool name that, if present in session history, triggers denial.

§deny_reason: String
§

MaxCallsInWindow

Deny if a tool pattern appears more than max times in the last window entries of the session history.

Provides sliding-window rate limiting without requiring wall-clock timestamps. A window of 0 means the entire session history.

Fields

§tool_pattern: PatternMatcher
§max: u64
§window: usize

Number of most-recent history entries to consider. 0 = all.

§deny_reason: String
§

MaxChainDepth

OWASP ASI08: Limit the depth of multi-agent call chains.

In multi-hop MCP scenarios, an agent can request another agent to perform actions on its behalf. This condition limits how deep such chains can go to prevent privilege escalation through agent chaining.

Fields

§max_depth: usize

Maximum allowed chain depth. This is an exclusive upper bound: a call chain with len > max_depth entries is denied. A value of 0 means only direct calls are allowed (empty chain); any upstream hop is denied. A value of 1 allows exactly one upstream agent, etc.

§deny_reason: String
§

AgentIdentityMatch

OWASP ASI07: Match on cryptographically attested agent identity claims.

Requires a valid X-Agent-Identity JWT header. Policies can match on:

  • issuer: Required JWT issuer (iss claim)
  • subject: Required JWT subject (sub claim)
  • audience: Required audience (aud claim must contain this value)
  • claims.<key>: Custom claim matching (e.g., claims.role == "admin")

Unlike AgentId which matches on a simple string, this condition provides cryptographic attestation of the agent’s identity via JWT signature verification.

Fields

§required_issuer: Option<String>

Required JWT issuer. If set, the identity’s iss claim must match.

§required_subject: Option<String>

Required JWT subject. If set, the identity’s sub claim must match.

§required_audience: Option<String>

Required audience. If set, the identity’s aud claim must contain this value.

§required_claims: HashMap<String, String>

Required custom claims. All specified claims must match. Keys are claim names, values are expected string values.

§blocked_issuers: Vec<String>

Blocked issuers. If the identity’s iss matches any, deny.

§blocked_subjects: Vec<String>

Blocked subjects. If the identity’s sub matches any, deny.

§require_attestation: bool

When true, fail-closed if no agent_identity is present. When false, fall back to legacy agent_id matching.

§deny_reason: String
§

AsyncTaskPolicy

MCP 2025-11-25: Async task lifecycle policy.

Controls the creation and cancellation of async MCP tasks. Policies can:

  • Limit maximum concurrent tasks per session/agent
  • Set maximum task duration before automatic expiry
  • Restrict task cancellation to the creating agent only

Fields

§max_concurrent: usize

Maximum number of concurrent active tasks. 0 = unlimited.

§max_duration_secs: u64

Maximum task duration in seconds. 0 = unlimited.

§require_self_cancel: bool

When true, only the agent that created a task can cancel it.

§deny_reason: String
§

ResourceIndicator

RFC 8707: OAuth 2.0 Resource Indicator validation.

Validates that OAuth tokens include the expected resource indicators. Resource indicators prevent token replay attacks by binding tokens to specific API endpoints or resource servers.

Fields

§allowed_resources: Vec<PatternMatcher>

Patterns for allowed resource URIs. Supports glob patterns. If non-empty, at least one pattern must match the token’s resource.

§require_resource: bool

When true, deny if the token has no resource indicator.

§deny_reason: String
§

CapabilityRequired

CIMD: Capability-Indexed Message Dispatch.

MCP 2025-11-25 introduces capability negotiation. This condition checks that the client has declared the required capabilities and has not declared any blocked capabilities.

Fields

§required_capabilities: Vec<String>

Capabilities that must be declared by the client. All listed capabilities must be present.

§blocked_capabilities: Vec<String>

Capabilities that must NOT be declared by the client. If any listed capability is present, deny.

§deny_reason: String
§

StepUpAuth

Step-up authentication trigger.

When the current authentication level is below the required level, the policy triggers a step-up authentication challenge instead of denying outright. This allows sensitive operations to require stronger authentication without blocking the session.

Fields

§required_level: u8

Required authentication level (maps to AuthLevel enum). 0=None, 1=Basic, 2=OAuth, 3=OAuthMfa, 4=HardwareKey

§deny_reason: String
§

CircuitBreaker

Circuit breaker check (OWASP ASI08).

Prevents cascading failures by temporarily blocking requests to tools that have been failing. The circuit breaker pattern has three states: Closed (normal), Open (blocking), HalfOpen (testing).

Fields

§tool_pattern: PatternMatcher

Pattern to match tool names for circuit breaker tracking.

§deny_reason: String
§

DeputyValidation

Confused deputy validation (OWASP ASI02).

Validates that the current principal is authorized to perform the requested action, preventing confused deputy attacks where a privileged agent is tricked into acting on behalf of an unprivileged attacker.

Fields

§require_principal: bool

When true, a principal must be identified in the context.

§max_delegation_depth: u8

Maximum allowed delegation depth. 0 = direct only.

§deny_reason: String
§

ShadowAgentCheck

Shadow agent detection.

Detects when an unknown agent claims to be a known agent, indicating potential impersonation or shadow agent attack. Fingerprints agents based on JWT claims, client ID, and IP.

Fields

§require_known_fingerprint: bool

When true, require the fingerprint to match a known agent.

§min_trust_level: u8

Minimum trust level required (0-4). 0=Unknown, 1=Low, 2=Medium, 3=High, 4=Verified

§deny_reason: String
§

SchemaPoisoningCheck

Schema poisoning protection (OWASP ASI05).

Tracks tool schema changes over time and alerts or blocks when schemas change beyond the configured threshold. Prevents rug-pull attacks where tool behavior changes maliciously.

Fields

§mutation_threshold: f32

Schema similarity threshold (0.0-1.0). Changes above this trigger denial.

§deny_reason: String
§

MinVerificationTier

Minimum verification tier enforcement.

Requires the agent’s verification tier to meet or exceed a minimum level. Fail-closed: if no verification tier is present in the context, denies.

Fields

§required_tier: u8

Required tier level (0-4). 0=Unverified, 1=EmailVerified, 2=PhoneVerified, 3=DidVerified, 4=FullyVerified

§deny_reason: String
§

RequireCapabilityToken

Capability-based delegation token enforcement.

Requires a valid capability token to be present in the evaluation context. Checks that the token’s holder matches the agent_id, and optionally restricts which issuers are trusted and requires minimum delegation depth.

§Security (MCP Gap #3 — Capability Delegation)

  • Fail-closed: missing token = Deny
  • Holder must match agent_id (prevents token theft)
  • Issuer allowlist prevents unauthorized token sources
  • Grant coverage is verified by the proxy layer before attaching to context

Fields

§required_issuers: Vec<String>

If non-empty, the token’s issuer must be in this list.

§min_remaining_depth: u8

Minimum remaining delegation depth required (0 = terminal tokens accepted).

§deny_reason: String
§

SessionStateRequired

Session state requirement (Phase 23.5).

Only allows actions when the session is in one of the specified states. Fail-closed: if no session_state is present in context, denies.

Fields

§allowed_states: Vec<String>

Allowed session states (e.g., [“active”, “init”]). State names are compared case-insensitively.

§deny_reason: String
§

RequiredActionSequence

Require an ordered (or unordered) sequence of tools in session history.

Ordered: subsequence match — tools must appear in order, not necessarily consecutive (e.g., A→C→B history matches A→B sequence). Unordered: all tools must appear anywhere in history (set semantics).

Max 20 steps. Fail-closed: empty/shorter history → Deny.

Fields

§sequence: Vec<String>

Tool names (lowercased at compile time).

§ordered: bool

true = ordered subsequence, false = unordered set.

§deny_reason: String
§

ForbiddenActionSequence

Deny if a sequence of tools has appeared in session history.

Ordered: subsequence match — if all tools found in order → Deny. Unordered: if all tools present anywhere → Deny.

Max 20 steps. Empty history → Allow (nothing forbidden yet).

§Known limitation (FIND-CREATIVE-004)

previous_actions is bounded at MAX_PREVIOUS_ACTIONS (10,000 entries). If an attacker performs the forbidden prefix actions and then issues enough additional tool calls to push the prefix out of the retained history window, the forbidden sequence will no longer be detected. This is an inherent trade-off of bounded history. When the history is at capacity, a warning is emitted so operators can investigate or increase monitoring. Consider pairing ForbiddenActionSequence with ForbiddenPreviousAction for individual high-risk tools that must never appear at all.

Fields

§sequence: Vec<String>

Tool names (lowercased at compile time).

§ordered: bool

true = ordered subsequence, false = unordered set.

§deny_reason: String
§

WorkflowTemplate

Workflow template: DAG of allowed tool transitions.

Non-governed tools pass through (no restriction). Governed tools must follow the DAG edges: the current tool must be a valid successor of the most recent governed tool in history, or an entry point if no governed tool has been called yet.

Max 50 steps. Cycles rejected at compile time via Kahn’s algorithm.

Fields

§adjacency: HashMap<String, Vec<String>>

Tool → valid successor tools.

§governed_tools: HashSet<String>

All tools appearing in the DAG.

§entry_points: Vec<String>

Tools with no predecessors (valid starting points).

§strict: bool

true = Deny on violation, false = warn only.

§deny_reason: String

Trait Implementations§

Source§

impl Clone for CompiledContextCondition

Source§

fn clone(&self) -> CompiledContextCondition

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompiledContextCondition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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