vetto 0.3.9

Daemon-less sandbox + security layer for AI coding agents (Landlock/Seatbelt, TUI statusline, post-session audit reports)
Documentation
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
//! Attack scenario registry: static catalog of security properties.
//!
//! Each scenario carries a fixed [`ClaimStrength`](super::model::ClaimStrength)
//! per platform target, a quorum rule for multi-vector scenarios, and a
//! mandatory `known_limitation`. An empty limitation is a registry lint
//! error: every claim must state what it does not prove.

use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};

use super::model::{Category, ClaimStrength};

/// Platform/tier target a strength entry applies to.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum Target {
    LinuxFull,
    LinuxFsOnly,
    LinuxSeccomp,
    Macos,
    Windows,
    WindowsSandboxVm,
}

impl Target {
    pub fn label(self) -> &'static str {
        match self {
            Target::LinuxFull => "linux-full",
            Target::LinuxFsOnly => "linux-fsonly",
            Target::LinuxSeccomp => "linux-seccomp",
            Target::Macos => "macos",
            Target::Windows => "windows",
            Target::WindowsSandboxVm => "windows-sandbox-vm",
        }
    }
}

/// Severity labels for the canonical registry rendering.
impl Severity {
    pub fn label(self) -> &'static str {
        match self {
            Severity::Blocker => "blocker",
            Severity::High => "high",
            Severity::Medium => "medium",
            Severity::Low => "low",
        }
    }
}

/// Severity if this scenario FAILs.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Severity {
    Blocker,
    High,
    Medium,
    Low,
}

/// One registered attack scenario (mirrors `tests/verify_ng/scenarios/*.toml`).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Scenario {
    pub id: String,
    pub category: Category,
    pub severity: Severity,
    /// Capabilities the runner must prove present (else NOT_APPLICABLE).
    pub required_caps: Vec<String>,
    /// Static strength ceiling per target (FM-10/FM-11).
    pub strength: BTreeMap<String, ClaimStrength>,
    /// Minimum number of independent agreeing vectors for a verdict
    /// (FM-13). `1` only for single-vector scenarios.
    pub quorum: usize,
    /// What this scenario does NOT prove. Must be non-empty.
    pub known_limitation: String,
    /// Residual risk text for PARTIAL targets. Required when any target
    /// is PARTIAL.
    #[serde(default)]
    pub residual_risk: String,
}

impl Scenario {
    pub fn strength_for(&self, target: Target) -> ClaimStrength {
        self.strength
            .get(target.label())
            .copied()
            // Unknown target: claim nothing.
            .unwrap_or(ClaimStrength::Unsupported)
    }

    /// Registry lint: non-empty limitation; quorum >= 1; PARTIAL targets
    /// require residual_risk text.
    pub fn lint(&self) -> Result<(), String> {
        if self.id.trim().is_empty() {
            return Err("scenario id is empty".to_string());
        }
        if self.quorum < 1 {
            return Err(format!("{}: quorum must be >= 1", self.id));
        }
        if self.known_limitation.trim().is_empty() {
            return Err(format!("{}: known_limitation must be non-empty", self.id));
        }
        if self.strength.values().any(|s| *s == ClaimStrength::Partial)
            && self.residual_risk.trim().is_empty()
        {
            return Err(format!(
                "{}: PARTIAL target requires residual_risk",
                self.id
            ));
        }
        Ok(())
    }
}

/// Statically registered scenarios (the TOML files under
/// `tests/verify_ng/scenarios/` are the source of truth for documentation;
/// this table is the compiled enforcement of the same contracts).
pub fn registry() -> Vec<Scenario> {
    vec![
        Scenario {
            id: "ORACLE-DECEIT-001".to_string(),
            category: Category::Aux,
            severity: Severity::Blocker,
            required_caps: vec!["spawn".to_string()],
            strength: BTreeMap::from([(Target::LinuxFull.label().to_string(), ClaimStrength::Strong)]),
            quorum: 1,
            known_limitation: "Proves oracle soundness only; says nothing about any enforcement backend."
                .to_string(),
            residual_risk: String::new(),
        },
        Scenario {
            id: "CONTROL-SPLIT-001".to_string(),
            category: Category::Aux,
            severity: Severity::Blocker,
            required_caps: vec!["spawn".to_string()],
            strength: BTreeMap::from([(Target::LinuxFull.label().to_string(), ClaimStrength::Strong)]),
            quorum: 1,
            known_limitation: "Proves nonce binding of the control pair only."
                .to_string(),
            residual_risk: String::new(),
        },
        Scenario {
            id: "FIXTURE-MUTATE-001".to_string(),
            category: Category::Aux,
            severity: Severity::High,
            required_caps: vec!["spawn".to_string()],
            strength: BTreeMap::from([(Target::LinuxFull.label().to_string(), ClaimStrength::Strong)]),
            quorum: 1,
            known_limitation: "Proves payload integrity checking only."
                .to_string(),
            residual_risk: String::new(),
        },
        Scenario {
            id: "ENV-POISON-001".to_string(),
            category: Category::Spawn,
            severity: Severity::Blocker,
            required_caps: vec!["spawn".to_string()],
            strength: BTreeMap::from([
                (Target::LinuxFull.label().to_string(), ClaimStrength::Strong),
                (Target::Macos.label().to_string(), ClaimStrength::Strong),
            ]),
            quorum: 1,
            known_limitation: "Proves diagnostic-env detection only; not a substitute for env scrub verification."
                .to_string(),
            residual_risk: String::new(),
        },
        Scenario {
            id: "GATE-VACUUM-001".to_string(),
            category: Category::Aux,
            severity: Severity::High,
            required_caps: vec![],
            strength: BTreeMap::from([(Target::LinuxFull.label().to_string(), ClaimStrength::Strong)]),
            quorum: 1,
            known_limitation: "Meta-test of the gate quotas; proves the gate cannot pass on an empty suite."
                .to_string(),
            residual_risk: String::new(),
        },
        Scenario {
            id: "HANG-GRANDCHILD-001".to_string(),
            category: Category::Proc,
            severity: Severity::High,
            required_caps: vec!["spawn".to_string(), "tree-sweep".to_string()],
            strength: BTreeMap::from([
                (Target::LinuxFull.label().to_string(), ClaimStrength::Strong),
                (Target::Windows.label().to_string(), ClaimStrength::Strong),
                (Target::LinuxFsOnly.label().to_string(), ClaimStrength::Partial),
                (Target::Macos.label().to_string(), ClaimStrength::Partial),
            ]),
            quorum: 1,
            known_limitation: "Proves deadline-aware collection, not general liveness of arbitrary payloads."
                .to_string(),
            residual_risk: "On fs-only/macOS the grandchild may outlive the group kill until the sweep budget expires; verdict is FAIL/INCONCLUSIVE, never PASS.".to_string(),
        },
        Scenario {
            id: "VFS-TRAV-001".to_string(),
            category: Category::FsRead,
            severity: Severity::Blocker,
            required_caps: vec!["spawn".to_string(), "landlock".to_string()],
            strength: BTreeMap::from([
                (Target::LinuxFull.label().to_string(), ClaimStrength::Strong),
                (Target::LinuxFsOnly.label().to_string(), ClaimStrength::Strong),
                (Target::Macos.label().to_string(), ClaimStrength::Partial),
                (Target::Windows.label().to_string(), ClaimStrength::Partial),
            ]),
            quorum: 2,
            known_limitation: "Covers symlink/hardlink/dotdot/rename vectors present in the payload set; new kernel path aliases need new vectors."
                .to_string(),
            residual_risk: "macOS Shape-A broad reads and Windows ACL fallback may expose entries outside the tail-deny list; strength ceiling PARTIAL there.".to_string(),
        },
        Scenario {
            id: "VFS-WRITE-001".to_string(),
            category: Category::FsWrite,
            severity: Severity::Blocker,
            required_caps: vec!["spawn".to_string(), "landlock".to_string()],
            strength: BTreeMap::from([
                (Target::LinuxFull.label().to_string(), ClaimStrength::Strong),
                (Target::LinuxFsOnly.label().to_string(), ClaimStrength::Strong),
                (Target::Macos.label().to_string(), ClaimStrength::Partial),
                (Target::Windows.label().to_string(), ClaimStrength::Partial),
            ]),
            quorum: 2,
            known_limitation: "Proves writes outside allowlist are denied for the covered vectors only; writes inside $PROJECT are allowed by design and out of scope (see threat-model non-goal #2)."
                .to_string(),
            residual_risk: "macOS Shape-A broad paths and Windows ACL fallback may permit writes through aliases outside the deny list; strength ceiling PARTIAL there.".to_string(),
        },
        Scenario {
            id: "NET-DNS-IPV6-001".to_string(),
            category: Category::Net,
            severity: Severity::Blocker,
            required_caps: vec!["spawn".to_string(), "netns".to_string()],
            strength: BTreeMap::from([
                (Target::LinuxFull.label().to_string(), ClaimStrength::Strong),
                (Target::LinuxFsOnly.label().to_string(), ClaimStrength::Partial),
                (Target::Macos.label().to_string(), ClaimStrength::Partial),
                (Target::Windows.label().to_string(), ClaimStrength::Partial),
            ]),
            quorum: 2,
            known_limitation: "Proves --net=off isolation only; allowlist relay modes need a separate broker suite."
                .to_string(),
            residual_risk: "Without a network namespace (fs-only/mac/win) only syscall/capability denial is proven, not absence of a route.".to_string(),
        },
        Scenario {
            id: "NET-EXFIL-001".to_string(),
            category: Category::Net,
            severity: Severity::Blocker,
            required_caps: vec!["spawn".to_string(), "netns".to_string()],
            strength: BTreeMap::from([
                (Target::LinuxFull.label().to_string(), ClaimStrength::Strong),
                (Target::LinuxFsOnly.label().to_string(), ClaimStrength::Partial),
                (Target::Macos.label().to_string(), ClaimStrength::Partial),
                (Target::Windows.label().to_string(), ClaimStrength::Partial),
            ]),
            quorum: 3,
            known_limitation: "Proves --net=off isolation only across the listed egress vectors; allowlist relay modes and TLS-through-allowed-API payload semantics need a separate broker suite (threat-model non-goal #1)."
                .to_string(),
            residual_risk: "Without netns (fs-only/mac/win) only syscall/capability denial is proven, not absence of a route. Per-domain egress without admin on Windows is UNPROVABLE.".to_string(),
        },
        Scenario {
            id: "PROC-ESC-001".to_string(),
            category: Category::Proc,
            severity: Severity::Blocker,
            required_caps: vec!["spawn".to_string(), "tree-sweep".to_string()],
            strength: BTreeMap::from([
                (Target::LinuxFull.label().to_string(), ClaimStrength::Strong),
                (Target::Windows.label().to_string(), ClaimStrength::Strong),
                (Target::LinuxFsOnly.label().to_string(), ClaimStrength::Partial),
                (Target::Macos.label().to_string(), ClaimStrength::Partial),
            ]),
            quorum: 1,
            known_limitation: "Post-mortem sweep is host-side observation of absence; a hostile scheduler can delay reparenting past the sweep budget (INCONCLUSIVE, never PASS)."
                .to_string(),
            residual_risk: "fs-only setsid orphans and macOS watchdog races are known residuals; they FAIL/advisory, never PASS.".to_string(),
        },
        Scenario {
            id: "PROC-TREE-001".to_string(),
            category: Category::Proc,
            severity: Severity::Blocker,
            required_caps: vec!["spawn".to_string(), "tree-sweep".to_string()],
            strength: BTreeMap::from([
                (Target::LinuxFull.label().to_string(), ClaimStrength::Strong),
                (Target::Windows.label().to_string(), ClaimStrength::Strong),
                (Target::LinuxFsOnly.label().to_string(), ClaimStrength::Partial),
                (Target::Macos.label().to_string(), ClaimStrength::Partial),
            ]),
            quorum: 2,
            known_limitation: "Proves process-tree containment for the covered escape shapes only; hostile scheduler delaying reparent past the sweep budget yields INCONCLUSIVE, never PASS."
                .to_string(),
            residual_risk: "fs-only setsid orphans and macOS watchdog races are known residuals; verdict is FAIL/INCONCLUSIVE, never PASS.".to_string(),
        },
        Scenario {
            id: "ENV-LEAK-001".to_string(),
            category: Category::Secrets,
            severity: Severity::Blocker,
            required_caps: vec!["spawn".to_string()],
            strength: BTreeMap::from([
                (Target::LinuxFull.label().to_string(), ClaimStrength::Strong),
                (Target::Macos.label().to_string(), ClaimStrength::Strong),
                (Target::Windows.label().to_string(), ClaimStrength::Strong),
            ]),
            quorum: 1,
            known_limitation: "Proves environment isolation and credential scrub under sealed SecurityContract: scrubbing of arbitrary host vars, sensitive credentials, PATH hygiene, internal Vetto vars, explicitly denied variables, and post-start mutation immutability; unknown exfil channels (covert timing, allowed-relay payloads) are out of scope."
                .to_string(),
            residual_risk: String::new(),
        },
        Scenario {
            id: "RACE-BINDING-001".to_string(),
            category: Category::Spawn,
            severity: Severity::Blocker,
            required_caps: vec!["spawn".to_string()],
            strength: BTreeMap::from([(Target::LinuxFull.label().to_string(), ClaimStrength::Strong)]),
            quorum: 1,
            known_limitation: "Proves spec/tier binding continuity in-process; a compromised host kernel is out of scope."
                .to_string(),
            residual_risk: String::new(),
        },
        Scenario {
            id: "CLEANUP-SIGKILL-001".to_string(),
            category: Category::Proc,
            severity: Severity::High,
            required_caps: vec!["spawn".to_string(), "tree-sweep".to_string()],
            strength: BTreeMap::from([
                (Target::LinuxFull.label().to_string(), ClaimStrength::Strong),
                (Target::Windows.label().to_string(), ClaimStrength::Strong),
                (Target::LinuxFsOnly.label().to_string(), ClaimStrength::Partial),
                (Target::Macos.label().to_string(), ClaimStrength::Partial),
            ]),
            quorum: 1,
            known_limitation: "Requires an external observer process/VM; cannot be self-proven from inside the harness under test."
                .to_string(),
            residual_risk: "fs-only/macOS orphans may survive a SIGKILLed harness; suite must run in a disposable VM there.".to_string(),
        },
        Scenario {
            id: "EVIDENCE-REDACT-001".to_string(),
            category: Category::Aux,
            severity: Severity::High,
            required_caps: vec![],
            strength: BTreeMap::from([(Target::LinuxFull.label().to_string(), ClaimStrength::Strong)]),
            quorum: 1,
            known_limitation: "Proves redaction of the known secret shapes; novel shapes need secretscan updates."
                .to_string(),
            residual_risk: String::new(),
        },
        Scenario {
            id: "MAC-SHAPE-001".to_string(),
            category: Category::FsRead,
            severity: Severity::High,
            required_caps: vec!["spawn".to_string(), "seatbelt".to_string()],
            strength: BTreeMap::from([(Target::Macos.label().to_string(), ClaimStrength::Partial)]),
            quorum: 1,
            known_limitation: "Proves the enforced profile is Shape-A + tail-deny byte-for-byte; read secrecy beyond tail-deny is UNPROVABLE on macOS native."
                .to_string(),
            residual_risk: "Any path outside the tail-deny list is readable by construction; use a Linux VM for strong read secrecy.".to_string(),
        },
        Scenario {
            id: "WIN-UNC-001".to_string(),
            category: Category::FsRead,
            severity: Severity::High,
            required_caps: vec!["spawn".to_string()],
            strength: BTreeMap::from([(Target::Windows.label().to_string(), ClaimStrength::Partial)]),
            quorum: 1,
            known_limitation: "Advisory until UNC/namespace-alias coverage is mapped; starts INCONCLUSIVE, never PASS on first implementation."
                .to_string(),
            residual_risk: r"Alternate path aliases (UNC, \\?\, mapped drives) may bypass ACL-shaped checks.".to_string(),
        },
        Scenario {
            id: "WIN-WSL-001".to_string(),
            category: Category::FsRead,
            severity: Severity::High,
            required_caps: vec!["spawn".to_string()],
            strength: BTreeMap::from([(Target::Windows.label().to_string(), ClaimStrength::Unsupported)]),
            quorum: 1,
            known_limitation: "WSL-interop boundary is unmapped; INCONCLUSIVE baseline until researched. Any PASS is an oracle bug."
                .to_string(),
            residual_risk: String::new(),
        },
    ]
}

/// Canonical rendering of the full compiled registry into deterministic
/// bytes: every semantically meaningful scenario field (id, category,
/// severity, required caps, strength map, quorum, known limitation,
/// residual risk) in a fixed order with an explicit version tag, scenarios
/// sorted by id. Any security-relevant registry change flips the bytes;
/// pure reordering does not. This is what [`FrozenSpec`] binds to — never
/// a bare list of scenario ids.
pub fn canonical_registry_bytes(scenarios: &[Scenario]) -> Vec<u8> {
    let mut sorted: Vec<&Scenario> = scenarios.iter().collect();
    sorted.sort_by(|a, b| a.id.cmp(&b.id));
    let mut out = String::from("vng-registry-v1;");
    for s in sorted {
        let mut caps = s.required_caps.clone();
        caps.sort();
        let mut strength: Vec<(&String, &super::model::ClaimStrength)> =
            s.strength.iter().collect();
        strength.sort_by(|a, b| a.0.cmp(b.0));
        let strength_s = strength
            .iter()
            .map(|(k, v)| format!("{k}={}", v.label()))
            .collect::<Vec<_>>()
            .join(",");
        out.push_str(&format!(
            "scenario[id={}|cat={}|sev={}|caps=[{}]|strength=[{}]|quorum={}|limit={}|residual={}];",
            s.id,
            s.category.label(),
            s.severity.label(),
            caps.join(","),
            strength_s,
            s.quorum,
            s.known_limitation,
            s.residual_risk
        ));
    }
    out.into_bytes()
}

/// Registry hash over the full canonical registry rendering.
pub fn registry_hash_full(scenarios: &[Scenario]) -> String {
    use sha2::{Digest, Sha256};
    let mut hasher = Sha256::new();
    hasher.update(canonical_registry_bytes(scenarios));
    super::frozen::hex_encode(&hasher.finalize())
}

/// Lint the whole registry. Used by tests and the `verify-ng lint` path.
pub fn lint_all(scenarios: &[Scenario]) -> Vec<String> {
    let mut errors = Vec::new();
    let mut seen = std::collections::BTreeSet::new();
    for s in scenarios {
        if !seen.insert(s.id.clone()) {
            errors.push(format!("duplicate scenario id {}", s.id));
        }
        if let Err(e) = s.lint() {
            errors.push(e);
        }
    }
    errors
}

#[cfg(test)]
mod registry_tests {
    use super::*;

    #[test]
    fn registry_lints_clean() {
        let reg = registry();
        assert!(reg.len() >= 10);
        assert_eq!(lint_all(&reg), Vec::<String>::new());
    }

    #[test]
    fn empty_limitation_is_rejected() {
        let mut s = registry().remove(0);
        s.known_limitation.clear();
        assert!(s.lint().is_err());
    }

    #[test]
    fn partial_without_residual_is_rejected() {
        let mut s = registry().remove(0);
        s.strength = BTreeMap::from([("linux-full".to_string(), ClaimStrength::Partial)]);
        s.residual_risk.clear();
        assert!(s.lint().is_err());
    }
}