1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Airlock - Agent RASP (Runtime Application Self-Protection)
//!
//! Provides runtime security inspection for AI agent tool calls:
//!
//! ## Three Inspection Layers
//!
//! 1. **Anti-RCE Pattern Matcher** (`patterns.rs`)
//! - Detects dangerous code patterns: eval(), exec(), __import__
//! - Catches obfuscation: base64 + eval combos
//! - Blocks shell injection: pipes, redirects, command substitution
//! - Prevents path traversal
//!
//! 2. **Financial Circuit Breaker** (`velocity.rs`)
//! - Spending velocity limits (e.g., max $1.00 in 10 seconds)
//! - Loop detection (same tool+args called repeatedly)
//! - Per-run tracking with automatic cleanup
//!
//! 3. **Data Exfiltration Shield** (`exfiltration.rs`)
//! - Domain whitelist for network tools
//! - Blocks raw IP addresses (prevents C2 connections)
//! - URL extraction from nested JSON payloads
//!
//! ## Operating Modes
//!
//! - **Shadow Mode** (default): Log violations but don't block - safe for rollout
//! - **Enforce Mode**: Block violations - production mode
//!
//! ## Usage
//!
//! ```ignore
//! use fd_policy::airlock::{AirlockInspector, AirlockConfig, InspectionContext};
//!
//! // Create inspector with configuration
//! let config = AirlockConfig::default(); // Shadow mode by default
//! let inspector = AirlockInspector::new(config);
//!
//! // Inspect a tool call
//! let ctx = InspectionContext {
//! run_id: run_id.clone(),
//! tool_name: "write_file".to_string(),
//! tool_input: serde_json::json!({"content": "hello"}),
//! estimated_cost_cents: Some(10),
//! };
//!
//! let result = inspector.inspect(&ctx).await;
//!
//! if !result.allowed {
//! // Tool call blocked (or logged in shadow mode)
//! println!("Blocked: {:?}", result.violation);
//! }
//!
//! // Record successful call for velocity tracking
//! inspector.record_call(&ctx).await;
//!
//! // Cleanup when run completes
//! inspector.clear_run(&run_id.to_string()).await;
//! ```
// Re-export main types for convenience
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use VelocityStats;