feat: add --deep MIR-based analysis via capsec-driver#52
Merged
Conversation
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.
Auths Commit Verification
Result: ✅ 1/1 commits verified |
Auths Commit Verification
Result: ✅ 2/2 commits verified |
Auths Commit Verification
Result: ✅ 3/3 commits verified |
Auths Commit Verification
Result: ✅ 4/4 commits verified |
Auths Commit Verification
Result: ✅ 5/5 commits verified |
Auths Commit Verification
Result: ✅ 6/6 commits verified |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
--deepflag tocargo capsec auditthat 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:
crates/capsec-deep/crate (excluded from workspace, requires nightly)capsec-driverbinary implementsrustc_driver::Callbacks::after_analysisTested 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.