168 lines
12 KiB
Markdown
168 lines
12 KiB
Markdown
# Security audit: R5.6 fingerprint switch, activated (9e87016)
|
|
|
|
Mode audit, fresh and blind. Scope: `git diff 59521dc 9e87016` (31 files, all present at HEAD),
|
|
branch `feature/rust-r5-pipeline-core`, working tree clean before and after. Contract:
|
|
`.claude/tasks/contracts/2026-10-25-rust-r5-6-rehearsal.md` (S1-S8 + Clarification 2026-10-25) and the
|
|
owner's activation brief. No file modified except this report; no network beyond semgrep's rule
|
|
download; no service key, no Supabase, no transfer tool, no `pnpm format`.
|
|
|
|
```
|
|
SECURITY — VERDICT: PASS
|
|
TOOL: semgrep 1.168.0 — p/security-audit, p/secrets, p/owasp-top-ten
|
|
SCOPE: 31 files
|
|
BLOCKING:
|
|
(none)
|
|
REPORTED (non-blocking):
|
|
- [LOW] rebase-exact-equality-no-sheet-id (pre-existing, R2) — crates/core/src/domain/report/rebase.rs:43
|
|
- [LOW] registry-and-declaration-check-public — crates/core/src/domain/sheet/fingerprint.rs:44, :103
|
|
- [LOW] snapshot-assets-outside-fingerprint (pre-existing trust model) — crates/core/src/domain/archive/snapshot_rules.rs:79
|
|
- [LOW] caller-built-export-input-trusted (pre-existing, documented) — crates/core/src/pdf/write/input.rs:205
|
|
- [LOW] new-lint-allow-in-test-file (not a security suppression) — crates/core/tests/r5_6_switch.rs:8
|
|
PROOF: semgrep 129 rules on 31 files → 0 findings; checklist 8 checks → 0 findings in scope (+1 guardrails WARN outside the diff); alias-path review 14 checks → 0 blocking, 5 LOW
|
|
```
|
|
|
|
## Tooling
|
|
|
|
- semgrep 1.168.0, pinned packs, `--metrics=off`: 129 rules run on the 31 changed files, 0 findings,
|
|
0 errors.
|
|
- Guardrails scanner (`~/.claude/skills/guardrails/scripts/scan.py --domain api,supabase`): 0 FAIL,
|
|
1 WARN, 1 MANUAL. The WARN (`SB-POLICY-NOT-OWNER`,
|
|
`supabase/migrations/20261008110000_anatomical_sheets.sql:1177`, `species_select_active`) is in a file
|
|
outside the diff: out of scope, not counted. MANUAL not reported.
|
|
- Hermetic tests run in the main tree (no file written outside `target/`):
|
|
- `cargo test -p faunosteo-core --features cli --locked`: `r5_6_switch` 14/14, `sheet_fingerprint` 11/11
|
|
(incl. `nesting_is_bounded_with_a_controlled_error`), `pdf_import` 4/4, `pdf_compare` 16/16;
|
|
lib unit `the_registered_pair_holds_one_way_for_its_sheet_only` 1/1.
|
|
- vitest `packages/core-wasm/tests/r5-6.n-1.test.ts` 2/2 and `apps/app/tests/unit/r5-6.switch.test.ts`
|
|
2/2 (BUILD_STAMP accepted, module current).
|
|
- `bash scripts/import-equine.sh --check` (compare-only, read before running): legacy-import 6 files
|
|
0 differences, draft 12 files 0 differences.
|
|
|
|
## Checklist (STEP 3), scoped to the diff
|
|
|
|
| Check | Result |
|
|
|---|---|
|
|
| Hardcoded secret / token / key / auth URL | none (added lines grepped; the hex values are public fingerprints) |
|
|
| SQL by concatenation | none (no SQL in the diff) |
|
|
| Unsanitised render (innerHTML, eval, raw) | none |
|
|
| Sensitive endpoint without authz | N/A: no endpoint, RPC or policy in the diff |
|
|
| Stack trace / internal path to the user | none new. `facade.rs:56` maps `LoadError::Fingerprint` to `invalid_sheet` with the refusal's Debug text (a recomputed hex or a serde reason about the page's own bundle), no path, no secret |
|
|
| Secret / PII in a log | none (no log call added) |
|
|
| Tracked `.env` / credential file | only `.env.example` tracked |
|
|
| Guardrails scanner | run, nothing in scope (see above) |
|
|
|
|
Anti-gaming (STEP 4): no new `nosemgrep`, `nosec`, `eslint-disable`, `@ts-ignore` in the diff. One new
|
|
`#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]` heads the new test file
|
|
`crates/core/tests/r5_6_switch.rs:8`. It is the shared header of 20+ integration test files (the core's
|
|
no-I/O and no-panic lints, which tests that read fixtures must relax), not a security-rule suppression:
|
|
reported LOW, not blocking.
|
|
|
|
## Alias paths attacked (the brief)
|
|
|
|
1. **`equivalence` crate-private.** `fingerprint.rs:72` is `pub(crate)`. Its one non-test caller is
|
|
`LoadedSheet::recognises_historical_stamp` (`loaded.rs:169`). The wasm crate references no
|
|
fingerprint item (`crates/wasm/src` grep empty).
|
|
2. **One decision point.** Every alias decision goes through `recognises_historical_stamp`
|
|
(`loaded.rs:163-171`): `build_sheet_snapshot` (`snapshot_rules.rs:62-64`, behind `archive.snapshot`
|
|
`ops.rs:361-363`), `rebase_report_on_sheet` (`rebase.rs:43-46`, reached by `session.rs:89` draft
|
|
restore and `session.rs:127` import), `sheet_line` (`compare/lines.rs:350-358`). The only other
|
|
reader of `TRUSTED_ALIASES` in `src` is the generator (`pipeline.rs:185`), which writes the
|
|
descriptive list into `sheet-ref.json`; that list is never read back for a decision
|
|
(`declared.aliases` is only passed to `check_declared`, `loaded.rs:199-204`).
|
|
3. **Forging the private verified state.** `verified_fingerprint` (`loaded.rs:75`) is a private field;
|
|
`from_bundle` is the only constructor (`loaded.rs:121-151`), `LoadedSheet` derives neither
|
|
`Deserialize` nor `Default`, struct-update syntax is impossible outside the module, and
|
|
`unsafe_code = "forbid"` applies to core and wasm (workspace lints, `Cargo.toml:55`, both crates
|
|
`[lints] workspace = true`). `Clone` copies the state with the document, which the recomputation then
|
|
re-proves. The wasm `SheetHandle` keeps its `LoadedSheet` private (`crates/wasm/src/lib.rs:27`), so a
|
|
page cannot mutate it.
|
|
4. **Recomputation at the decision.** The predicate requires a verified value, `verified ==
|
|
reference.document_sha256`, the registry pair `(sheet_id, alias → verified)` in one direction, and
|
|
`document_fingerprint(&self.document) == verified` now. A mutated pub `document` or `reference`, a
|
|
cloned sheet re-pointed to another sheet id, a v0 sheet, or a stamp the registry does not bind all
|
|
return false (tests `a_mutated_document_or_reference_never_keeps_the_alias`,
|
|
`the_historical_value_on_another_sheet_id_is_not_recognised`). A bundle with another sheet id and
|
|
the genuine document verifies but never matches the registry (entry pinned to the equine id); a
|
|
bundle with the equine id and other content verifies to another value the registry does not bind.
|
|
Granting the alias therefore needs the genuine content (SHA-256 preimage otherwise).
|
|
5. **Injectivity of the fingerprinted form.** The value hashes the typed reading serialised back. Checked
|
|
for collapses that would let two behaviours share a value: no `#[serde(skip)]` or `flatten` in
|
|
`sheet/schema.rs`; `skip_serializing_if = "Option::is_none"` (lines 169, 176) round-trips; the
|
|
untagged enums (`SheetView`, `Geometry`) carry distinguishing fields. The app consumes the same
|
|
typed document, so text-only differences the reading erases are never behaviour.
|
|
6. **v0 / v1 and direction.** No block = v0, unverified, no privilege (`check_reference` returns
|
|
`Ok(false)`, `loaded.rs:196-198`); an unverified v0 sheet carrying the canonical value still
|
|
rebases an old report and its direct export is refused (`SheetMismatch`, test
|
|
`the_direct_export_on_an_unverified_v0_sheet_with_the_canonical_value_is_refused`). The registry is
|
|
consulted only as alias → canonical, so a v0 (rollback) sheet never recognises a `v1` stamp.
|
|
`check_declared` refuses a declared value that is a registered alias or not 64 lowercase hex
|
|
(`fingerprint.rs:112-118`).
|
|
7. **`null` and malformed blocks.** `present_block` (`loaded.rs:46-50`) turns an explicit `null` into a
|
|
shape error; `DeclaredFingerprint` is `deny_unknown_fields` with required `convention` and
|
|
`aliases` (`loaded.rs:52-57`); a string block and an unknown key are refused (tests). A misspelt key
|
|
on the non-strict `BundledRef` only downgrades to v0: fail-closed, no privilege.
|
|
8. **Aliases never from a report, archive or bundle.** Archives cannot carry one: `SheetSnapshotRef`
|
|
and the snapshot are `deny_unknown_fields` (`archive/snapshot.rs:42, 59`); the archive reader keeps
|
|
strict equality between snapshot and report stamps (`archive/read.rs:116-119`, unchanged).
|
|
9. **Export input strict.** `assert_exportable` (`pdf/write/input.rs:204-210`) is unchanged by the diff:
|
|
strict sheet id and stamp equality, no registry. The alias only reaches an archive through the
|
|
core-built snapshot of a verified sheet.
|
|
10. **`report:compare`.** The alias line prints both raw values truncated to 12 chars through `esc`
|
|
(`compare/lines.rs:366-376`); `same_sheet` still requires the sheet id; the bin reads the seed's
|
|
block through the same `present_block` and `from_bundle` verification (`bin/report_compare.rs:40-44,
|
|
66`).
|
|
11. **`canonical_json` depth.** Bounded at `MAX_CANONICAL_DEPTH = 128` with `CanonicalError::TooDeep`
|
|
(`fingerprint.rs:132-154`), above serde_json's parse limit (127 nested containers accepted), so
|
|
every parsed bundle fits and a value built in code beyond it errors instead of overflowing the stack.
|
|
Tested at 128 / 129, arrays and objects.
|
|
12. **Recomputation cost.** In the predicate the recomputation is the last conjunct, after the registry
|
|
match: a forged or unknown stamp costs a string compare, only the registered historical stamp
|
|
triggers one recomputation (one per export snapshot, rebase or compare line). The load recomputes
|
|
once per `SheetHandle` when a block is present (page runtime, `runtime.ts:322`, and each import
|
|
worker, `handler.ts:48`), O(document), 302,794 B for the equine draft. Not attacker-amplifiable:
|
|
the bundle is build-time, a report triggers at most one recomputation per call. The 14 switch tests
|
|
(loads, imports, exports) run in 0.81 s in a debug build.
|
|
13. **Seed artifacts.** Only `draft/sheet-ref.json` and `draft/report-migration-map.json` change.
|
|
`document.json` (sha256 27c7383c…), `assets/horse.svg` (0ea5202f…) and `equine_draft.sql`
|
|
(c5a24312…) hash identically at 59521dc and HEAD. The committed block is consistent: value
|
|
`12d78872…`, convention `v1`, alias `27c7383c…`, which is the registry entry and the old file-bytes
|
|
hash. The migration map changes only its `documentSha256`.
|
|
14. **Oracles, goldens, N-1.** 0 files changed under `crates/core/tests/oracles`, `crates/core/tests/pdf`,
|
|
`apps/app/tests/fixtures`, `packages/core-wasm/tests/n-1`. The new
|
|
`crates/core/tests/fixtures/r5-6/pre-switch/{sheet-ref,report-migration-map}.json` are byte-identical
|
|
to the 59521dc seed files (sha256 2c0716f1…, 4139c51d…), so the redirected historical tests read
|
|
the real pre-switch inputs and cannot mask an anatomical change. Exact-equality semantics are
|
|
unchanged and documented as no proof of content (`fingerprint.rs:13-18`).
|
|
|
|
## Reported findings (LOW, non-blocking)
|
|
|
|
**L1. Rebase exact-equality branch has no sheet-id check** — `crates/core/src/domain/report/rebase.rs:43`.
|
|
Pre-existing since R2, unchanged in meaning: a report of another sheet id stamped with the current
|
|
sheet's value skips the rebase. The new alias branch does check the sheet id. Hint: add
|
|
`report.sheet.sheet_id == sheet.reference.sheet_id` to the equality branch in a later step (behaviour
|
|
change, owner decision).
|
|
|
|
**L2. Registry and declaration check stay public** — `crates/core/src/domain/sheet/fingerprint.rs:44`
|
|
(`TRUSTED_ALIASES`), `:103` (`check_declared`). Neither grants anything by itself and no consumer misuses
|
|
them today (integration tests and the generator need them), but a future crate consumer could rebuild an
|
|
alias decision from the registry without the recomputation. Hint: `#[doc(hidden)]` plus a doc line, or
|
|
move the tests in-crate and make both `pub(crate)`.
|
|
|
|
**L3. Archived drawings are outside the document fingerprint** —
|
|
`crates/core/src/domain/archive/snapshot_rules.rs:79` (`snapshot_assets(sheet)`). A hand-made bundle with
|
|
the genuine document but other SVG texts would archive them under the historical (or the canonical)
|
|
stamp. Pre-existing trust model (the bundle is trusted for what it declares, `fingerprint.rs:15-18`); the
|
|
alias adds no privilege the canonical stamp did not already have. Hint: bind asset hashes into the
|
|
document or check `asset_hashes` against the texts at load, if the threat model ever includes
|
|
non-build bundles.
|
|
|
|
**L4. Caller-built export input trusted for its self-consistent report and snapshot** —
|
|
`crates/core/src/pdf/write/input.rs:205`. A page script can hand the export any matching pair; the
|
|
registry is never consulted there and every reader decides again on import. Documented residual,
|
|
unchanged by the diff.
|
|
|
|
**L5. New lint allow in a test file** — `crates/core/tests/r5_6_switch.rs:8`. Shared test-file
|
|
convention for the core's I/O and panic lints, not a security suppression.
|
|
|
|
SECURITY — VERDICT: PASS
|