Commit 5a80709
committed
feat: add --deep MIR-based analysis via capsec-driver
Adds a `--deep` flag to `cargo capsec audit` that uses rustcs MIR
(Mid-level IR) to analyze all crates in the dependency tree, catching
authority usage that syntactic analysis misses — macro-expanded FFI
calls try_call!, trait dispatch, and generic instantiation.
Architecture:
- New `crates/capsec-deep/` crate (excluded from workspace, requires nightly)
- `capsec-driver` binary implements `rustc_driver::Callbacks::after_analysis`
- Walks MIR BasicBlocks → TerminatorKind::Call → extracts DefId targets
- Classifies calls against authority patterns via def_path_str
- Detects FFI calls via tcx.is_foreign_item — sees through macro wrappers
- Filters std/core/alloc and proc-macro crates to reduce noise
- Uses RUSTC_WRAPPER to analyze all crates including transitive dependencies
- Communicates findings via JSONL temp file ($CAPSEC_DEEP_OUTPUT)
- CLI reads JSONL, patches crate names/versions to match Cargo metadata,
deduplicates against syntactic findings, merges into unified output
Tested on heartwood: 613 → 837 findings, 12 → 26 crates analyzed.
New findings include std::net socket config calls, std::fs::OpenOptions,
std::env::temp_dir, and FFI calls resolved through macros that the
syntactic scanner could not see.1 parent 5f0bddd commit 5a80709
17 files changed
Lines changed: 756 additions & 1 deletion
File tree
- crates
- capsec-deep
- src
- tests/fixtures
- cargo-capsec/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Binary file not shown.
0 commit comments