Commit 03fdd9f
feat(bridge): split phantom into phantom-declared vs phantom-transitive (#76)
## Summary
The Track E sweep across 29 Cargo CVE issues revealed that the previous
bridge classifier marked **any** crate without a direct `use <crate>`
statement as `reach=phantom`, conflating two very different remediation
paths:
- **True phantom (`PhantomDeclared`)** — crate IS in a `Cargo.toml`
`[dependencies]` / `[workspace.dependencies]` block but never imported.
Fix: `cargo machete --fix` strips the dep and the whole subtree drops
from `Cargo.lock`. **file-soup#50** is the canonical case.
- **Misclassified (`PhantomTransitive`)** — crate is NOT in any
`Cargo.toml`; pulled in transitively by a parent. Local strip is
impossible; the fix requires bumping the parent past the affected
version. Of 28 non-pilot Track E repos, **~26 fell here** (Batch A 7/7
misclassified, Batch B almost certainly similar, Cohort E-2 4/5
misclassified per #75).
## What changed
- **Enum split**: `ReachabilityStatus::Phantom` → `PhantomDeclared` /
`PhantomTransitive`. JSON wire values (serde `rename_all = kebab-case`)
are now `phantom-declared` / `phantom-transitive`.
- **Evidence shape**: `ReachabilityEvidence` gains optional `parent_dep`
(populated only when transitive AND identifiable via Cargo.lock).
- **Reachability scan**: new
`check_reachability_with_manifest(project_dir, crate, declared_deps,
parent_map)` returns the correct variant. Lookup is normalised
(underscore↔hyphen, lowercase) so a CVE feed reporting `serde_json`
matches a manifest line `serde-json`.
- **Parent identification**: `lockfile::collect_cargo_parents` parses
`Cargo.lock`'s `dependencies = [...]` arrays and BFS-walks from each
direct dep, attributing every reachable transitive (first BFS to reach
wins). Best-effort — returns empty map on missing/unparseable lockfile,
and `classify` falls back to "an upstream parent dependency" phrasing.
- **Classifier**: `classify::classify` no longer takes `is_direct` — the
evidence's status variant already carries that info. Three-way output
(Mitigable / Unmitigable / Informational) is unchanged. The rationale
and fix-action diverge:
- `PhantomDeclared`: *"Strip from Cargo.toml — run `cargo machete --fix`
(or remove the dependency line manually) for `<crate>`."*
- `PhantomTransitive`: *"Pulled in transitively by `<parent>` — fix
requires bumping the parent dependency past the affected version of
`<crate>`. No local strip is possible."*
- **Schema bump**: `BridgeReport::schema_version` 0.1.0 → 0.2.0 to flag
the reach-field semantics change.
- **No new deps**: reuses the existing in-house TOML / Cargo.lock string
parsers (consistent with `collect_direct_cargo_dependencies`).
## Test coverage
13 new tests across the three bridge modules:
**`bridge::reachability`** (6 new):
- `phantom_declared_when_crate_in_cargo_toml_but_no_use`
- `phantom_transitive_when_crate_not_in_cargo_toml` (parent identified)
- `reachable_when_declared_and_used`
- `phantom_transitive_with_unknown_parent_is_still_classified`
- `phantom_classification_normalises_underscore_to_hyphen`
- `phantom_declared_resolves_workspace_member_dep` (workspace-member
declared dep)
**`bridge::lockfile`** (3 new):
- `parent_map_identifies_direct_to_transitive_path`
- `parent_map_returns_empty_when_no_lockfile`
- `parent_map_normalises_underscore_to_hyphen`
**`bridge::classify`** (4 new, rewritten old ones):
- `test_phantom_declared_recommends_machete_strip`
- `test_phantom_transitive_recommends_parent_bump`
- `test_phantom_transitive_unknown_parent_falls_back_gracefully`
- `test_phantom_variants_both_classify_informational`
All 38 bridge-module tests pass; full suite (327 lib + integration)
green; `cargo check` clean on default features (bridge is feature-gated
behind `http`).
## Files touched
| File | +/- |
|---|---|
| `src/bridge/mod.rs` | +35 / -14 |
| `src/bridge/reachability.rs` | +213 / -18 |
| `src/bridge/classify.rs` | +109 / -52 |
| `src/bridge/lockfile.rs` | +244 / -7 |
## Related work
- panic-attack#74 — vendored-pin allowlist (Cohort E-3). With this PR,
the classifier no longer falsely recommends stripping vendored-TLS /
build-script-only crates, because those would only be in scope when
they're `PhantomDeclared` (i.e., genuinely in `Cargo.toml`). The
allowlist still needs to ride on top to handle e.g. `openssl-sys = {
features = ["vendored"] }`.
- panic-attack#75 — Dioxus/GTK informational (Cohort E-2). With
parent-dep identification, the genuine presswerk case will now be
labelled with `parent_dep: "dioxus"` (or `wry`, whichever the BFS
reaches first).
- file-soup#50 — canonical `PhantomDeclared` case.
Closes #32 (Track C/E sweep parent).
## Test plan
- [x] `cargo check --features http` clean
- [x] `cargo check` (default features) clean
- [x] `cargo test --features http --lib bridge::` — 38 passed
- [x] `cargo test --features http` — full suite green (327 +
integration)
- [ ] Re-run Track E sweep against ~5 sample repos and confirm
previously-`phantom` findings now split correctly into
declared/transitive cohorts (post-merge validation)
Co-authored-by: hyperpolymath <hyperpolymath@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 1811b7b commit 03fdd9f
4 files changed
Lines changed: 601 additions & 73 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
30 | | - | |
31 | 35 | | |
32 | 36 | | |
33 | | - | |
34 | | - | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
39 | | - | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
43 | | - | |
| 47 | + | |
| 48 | + | |
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
65 | 76 | | |
66 | 77 | | |
67 | 78 | | |
| |||
183 | 194 | | |
184 | 195 | | |
185 | 196 | | |
186 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
187 | 207 | | |
188 | 208 | | |
189 | 209 | | |
190 | | - | |
| 210 | + | |
| 211 | + | |
191 | 212 | | |
192 | 213 | | |
193 | 214 | | |
| |||
200 | 221 | | |
201 | 222 | | |
202 | 223 | | |
| 224 | + | |
203 | 225 | | |
204 | 226 | | |
205 | 227 | | |
206 | 228 | | |
207 | | - | |
208 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
209 | 233 | | |
210 | 234 | | |
211 | | - | |
212 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
213 | 241 | | |
214 | 242 | | |
215 | 243 | | |
216 | 244 | | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
222 | 253 | | |
223 | 254 | | |
224 | | - | |
225 | | - | |
| 255 | + | |
| 256 | + | |
226 | 257 | | |
227 | 258 | | |
228 | | - | |
| 259 | + | |
229 | 260 | | |
230 | 261 | | |
231 | 262 | | |
232 | | - | |
233 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
234 | 269 | | |
235 | 270 | | |
236 | 271 | | |
237 | 272 | | |
238 | 273 | | |
239 | 274 | | |
240 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
241 | 292 | | |
242 | 293 | | |
243 | | - | |
| 294 | + | |
244 | 295 | | |
245 | 296 | | |
246 | 297 | | |
247 | 298 | | |
248 | 299 | | |
249 | | - | |
| 300 | + | |
250 | 301 | | |
251 | 302 | | |
252 | 303 | | |
253 | 304 | | |
254 | 305 | | |
255 | 306 | | |
256 | | - | |
| 307 | + | |
257 | 308 | | |
258 | 309 | | |
259 | 310 | | |
260 | 311 | | |
261 | 312 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
268 | 319 | | |
269 | 320 | | |
0 commit comments