Skip to content

Commit 48c8a8f

Browse files
committed
chore: remove build files, add readme
1 parent d8cba43 commit 48c8a8f

7 files changed

Lines changed: 62 additions & 0 deletions

File tree

crates/capsec-deep/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/target
2+
*.o
3+
*.d
4+
# Binaries produced when testing the driver on fixture files
5+
/clean
6+
/simple_fs
7+
/macro_ffi
8+
/capsec_test

crates/capsec-deep/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# capsec-deep
2+
3+
MIR-based deep analysis driver for capsec. Uses `rustc`'s Mid-level IR to detect ambient authority usage that syntactic analysis misses — macro-expanded FFI calls, trait dispatch, and generic instantiation.
4+
5+
## Requirements
6+
7+
- Nightly Rust toolchain (pinned in `rust-toolchain.toml`)
8+
- `rustc-dev` and `llvm-tools` components
9+
10+
## Install
11+
12+
```bash
13+
cd crates/capsec-deep
14+
cargo install --path .
15+
```
16+
17+
This installs the `capsec-driver` binary, which `cargo capsec audit --deep` invokes automatically.
18+
19+
## How it works
20+
21+
`capsec-driver` is a custom Rust compiler driver. When invoked via `RUSTC_WRAPPER`, it intercepts every crate compilation, runs the normal compiler pipeline through type checking, then walks the MIR of every function looking for:
22+
23+
- **Authority calls**`std::fs::*`, `std::net::*`, `std::env::*`, `std::process::*` resolved through the full type system (including macro expansion)
24+
- **FFI calls** — any call to a `DefKind::ForeignFn` item (catches `-sys` crate wrappers like `libgit2-sys`, `sqlite3-sys`)
25+
26+
Findings are written as JSONL to a temp file, which the main `cargo-capsec` CLI reads, merges with syntactic findings, and feeds into the cross-crate export map system for transitive propagation.
27+
28+
## Architecture
29+
30+
```
31+
cargo capsec audit --deep
32+
└→ cargo check (with RUSTC_WRAPPER=capsec-driver)
33+
└→ capsec-driver replaces rustc for each crate
34+
└→ after_analysis callback:
35+
1. Walk MIR BasicBlocks → TerminatorKind::Call
36+
2. Extract callee DefId → tcx.def_path_str()
37+
3. Classify against authority patterns
38+
4. Check tcx.is_foreign_item() for FFI
39+
5. Write JSONL to $CAPSEC_DEEP_OUTPUT
40+
```
41+
42+
## Standalone testing
43+
44+
```bash
45+
# Test on a single file
46+
CAPSEC_DEEP_DEBUG=1 cargo run -- --edition 2024 tests/fixtures/simple_fs.rs
47+
48+
# Test FFI detection through macros
49+
CAPSEC_DEEP_DEBUG=1 cargo run -- --edition 2024 tests/fixtures/macro_ffi.rs
50+
```
51+
52+
## Excluded from workspace
53+
54+
This crate requires nightly and is listed in the workspace `exclude` list. It builds independently and does not affect `cargo test --workspace` or `cargo check --workspace` on stable.

crates/capsec-deep/capsec_test

-452 KB
Binary file not shown.

crates/capsec-deep/clean

-452 KB
Binary file not shown.
-1.25 KB
Binary file not shown.
Binary file not shown.

crates/capsec-deep/simple_fs

-456 KB
Binary file not shown.

0 commit comments

Comments
 (0)