docs(docs): R5.6 rehearsal gates, export alias gap stated, audits
This commit is contained in:
1 parent
6ade9176d9
commit
65fa30893d
4 files changed
+176
-4
No files matched your search
@@ -0,0 +1,142 @@
|
||||
# Security audit: R5.6 fingerprint switch rehearsal (worktree 943a25a + `r5-6-switch.patch`, seed switched)
|
||||
|
||||
- date: 2026-10-25 | mode: audit (delta), fresh run | contract `.claude/tasks/contracts/2026-10-25-rust-r5-6-rehearsal.md` (S1-S8)
|
||||
- scope: `git -C <worktree> diff HEAD`, 28 files (9 Rust sources, Cargo.toml, 8 Rust test files and 2 fixtures,
|
||||
5 TypeScript test files, package.json, rust-check.sh, .prettierignore, the two switched seed files). Worktree:
|
||||
`/tmp/claude-1000/-home-bchanot-Documents-faunosteo/3571c861-cd6e-4751-a25e-c26da95beb85/scratchpad/r56wt`.
|
||||
`git apply --check -R` of the stored patch is clean there, so the worktree is exactly the patch.
|
||||
- isolation (S7) checked: main tree at 6ade917, seed `sheet-ref.json` still `27c7…`, `fingerprint.rs` still
|
||||
"PREPARED, NOT ACTIVE", the main-tree diff since 943a25a touches only `.claude/` and RUST.md.
|
||||
- untouched, checked file by file: `domain/archive/*` (incl. `read.rs`), `domain/session.rs`, `domain/report/read.rs`,
|
||||
`pdf/read/*`, `pdf/import.rs`, `pdf/json_js.rs`, `packages/core-wasm/tests/n-1`, `crates/core/tests/oracles`,
|
||||
`apps/app/tests/fixtures`, `tests/pdf/LEDGER.tsv`, `Cargo.lock`, `deny.toml`. Seed `document.json`, `horse.svg`,
|
||||
`equine_draft.sql` identical to HEAD; `sha256sum document.json` = `27c7383c…2660` (the registered alias).
|
||||
- hermetic runs in the worktree (`CARGO_TARGET_DIR=<worktree>/target`): `--features cli` r5_6_switch 8,
|
||||
sheet_fingerprint 10, pdf_compare 16, pdf_import 4; `--features curation` curation_draft 20, curation_review 12;
|
||||
vitest app `r5-6.switch` 2, core-wasm `r5-6.n-1` 1 (resolves the worktree's `packages/core-wasm`). All green.
|
||||
- not done: no service key, no Supabase, no transfer tool, no delete, no code edited, no `pnpm format`. The only
|
||||
network access was semgrep fetching its three pinned packs (metrics off).
|
||||
|
||||
## Focus answers
|
||||
|
||||
**Forged, unknown, foreign-sheet or unverified stamp counted as the same document?** Not in the readers.
|
||||
`equivalence` (`fingerprint.rs:63-75`) admits only the registry pair, one way (alias stamped, canonical current),
|
||||
bound to the sheet id. A forged 64-hex stamp is `Different` and rebases (`r5_6_switch.rs:169-179`); a case-changed
|
||||
one is refused by the v3 contract; a foreign sheet id matches no entry and fails the sheet-id checks
|
||||
(`rebase.rs:43-48`, `input.rs:212`). `check_reference` (`loaded.rs:161-180`) recomputes `v1` from the same typed
|
||||
document the index is built from, so `fingerprint_verified` implies the loaded content is the registered content.
|
||||
The pair itself is bound to one content: sha256 of the bytes is the alias, `v1` of the same bytes is the canonical
|
||||
value (curation_draft `the_document_fingerprint_is_v1_and_its_bytes_keep_the_historical_alias`, plus my sha256sum).
|
||||
Rebase and report:compare grant the alias only on a verified sheet (`rebase.rs:43-48`, `lines.rs:356`). The export
|
||||
check is the exception: see M1.
|
||||
|
||||
**Does M1 write a snapshot that is not the trusted document, or loosen archive checks?** Through the application,
|
||||
no: `export.ts:146` always builds the snapshot with `archive.snapshot` from the loaded sheet, and an old stamp only
|
||||
survives to export when that sheet was verified (otherwise rebase moved the report first). `archive/read.rs:116-119`
|
||||
is unchanged and strict; the mixed envelope is still rejected (`r5_6_switch.rs:185-188`). At the core boundary the
|
||||
binding is not enforced (M1).
|
||||
|
||||
**Can a v0 reference gain alias privilege?** At load, no: no block means `fingerprint_verified = false`, and a v0
|
||||
reference carrying the canonical value still rebases an old report (`r5_6_switch.rs:255-263`). At export, yes,
|
||||
if a caller pairs an old report with a snapshot cut from such a sheet (M1).
|
||||
|
||||
**Do the declared test rules hide a content difference?** No. Each rule is targeted and fails loudly on anything
|
||||
else. `curation_draft` `r5_6_rule` asserts the pre-switch value is the alias, moves only that value, adds the block,
|
||||
then compares whole bytes through the generator's formatter; the pre-switch copies are pinned to the frozen R5.1
|
||||
ledger (sha and length). `pdf_compare` `r5_6_rule` rewrites only the "matches the bundled sheet" line of
|
||||
non-migrated blocks into the alias line; a `!!` line or any other drift still mismatches, and the alias count is
|
||||
pinned (77). O7, O10, the R2 Zod oracle, the R5.1 ledger and `seed.golden` read the pre-switch files; their
|
||||
post-switch twins (`o7_after_r5_6_…`, `o10_on_the_switched_seed_…`, `the committed migration map after R5.6`)
|
||||
allow the stamp alone to move. `migratedBeforeR56` changes only `report.sheet.documentSha256`; observations
|
||||
still go through the switched map, so a mapping change would break the byte goldens.
|
||||
|
||||
**Wasm sha2 and the load-time fingerprint: cost or DoS?** The hasher is reached only from `loaded.rs:175` and the
|
||||
pipeline (`pipeline.rs:174`). Archive snapshots and imported files are never fingerprinted, and the bundle is
|
||||
build-time content. The cost is one validation, one JCS and one SHA-256 of a 296 KB document per sheet handle
|
||||
(page plus each import worker): the 8-test switch suite with its dozen loads runs in 0.46 s in a debug build.
|
||||
`sha2 0.11.1` was already locked; the worker keeps its own dependency. No attacker-driven DoS. Two LOWs below
|
||||
(L4, L5).
|
||||
|
||||
## Findings
|
||||
|
||||
### M1 [MEDIUM] The export grants the alias on the snapshot's word, with no verified sheet behind it
|
||||
|
||||
`crates/core/src/pdf/write/input.rs:205-213` (`assert_exportable`) and `:238-248` (`keep_the_report_stamp`)
|
||||
call `equivalence` with the snapshot's own `reference.document_sha256` as "current". The export never sees a
|
||||
`LoadedSheet`, so `fingerprint_verified` is not consulted. The snapshot document is a lean cut and cannot be
|
||||
re-hashed. As a result:
|
||||
|
||||
- `export_from_envelope` (`pdf/write/export.rs:117-136`, cargo only) took a mixed envelope (report `27c7…`,
|
||||
snapshot `12d7…`, any lean document) as `sheet_mismatch` before the patch. It now accepts it and writes the
|
||||
snapshot under `27c7…`, a self-consistent envelope that the strict reader keeps. The writer normalises what
|
||||
the reader rejects.
|
||||
- A snapshot cut from an unverified v0 reference that carries the canonical value, exported with an old report,
|
||||
gets the alias that rebase and report:compare deny for the same sheet.
|
||||
- `packages/core-wasm/tests/r5-6.n-1.test.ts:46-49` feeds a hand-edited snapshot and the core accepts it, which
|
||||
shows there is no provenance check.
|
||||
- RUST.md §11.20 (main tree, lines 3538-3545) says M1 "needs the loaded sheet's `fingerprint_verified`". At this
|
||||
site it does not. Contract S1's "with the loaded sheet's `v1` value recomputed … at load" holds only as an
|
||||
application-flow precondition.
|
||||
|
||||
Not exploitable today. The only shipped caller builds the snapshot from the verified loaded sheet. Archives are
|
||||
unsigned, so anyone can already write a `27c7/27c7` envelope around arbitrary content: no capability is gained.
|
||||
This is a trust-boundary gap, not a vulnerability.
|
||||
Hint: make the M1 decision where verification is known. `build_sheet_snapshot` / `archive.snapshot` can stamp the
|
||||
report's value when `sheet.fingerprint_verified` and the pair is `TrustedAlias`, and `assert_exportable` goes back
|
||||
to strict equality (that also keeps `export_from_envelope` strict). This needs an S2 scope amendment
|
||||
(`snapshot_rules.rs`). Otherwise, state the precondition at `input.rs:232-237` and correct RUST.md §11.20.
|
||||
|
||||
### L1 [LOW] `"fingerprint": null` reads as no block (v0)
|
||||
`crates/core/src/domain/sheet/loaded.rs:38-39`: `#[serde(default)] Option<…>` maps `null` to `None`. A present but
|
||||
null block is not refused, against S3's "a present block is strict". It fails closed: no privilege, old reports
|
||||
rebase. Hint: refuse an explicit `null`, for example with a custom deserializer.
|
||||
|
||||
### L2 [LOW] `BundledRef` accepts unknown keys, so a misspelt block loads as v0
|
||||
`loaded.rs:30-40`: `DeclaredFingerprint` is strict, but its parent is not. A typo such as `fingerprints` silently
|
||||
yields an unverified sheet. This fails closed, and the struct shape predates the patch. Hint:
|
||||
`deny_unknown_fields` on `BundledRef`, if every bundle producer (vite plugin, report_compare `SeedRef`, tests)
|
||||
emits only known keys.
|
||||
|
||||
### L3 [LOW] Verification state and verified value are public mutable fields
|
||||
`loaded.rs:53` (`reference`) and `:66` (`fingerprint_verified`) are `pub`. Crate code holding `&mut LoadedSheet`
|
||||
could change one without the other. No such writer exists today. Hint: private fields with getters.
|
||||
|
||||
### L4 [LOW] A warning the drafts allow makes a v1 bundle unloadable and the generator fail
|
||||
`fingerprint.rs:228-231` refuses any issue, warnings included. `validate.rs:366-380` (`annotation.no_findings`,
|
||||
documented "allowed in a draft") and `:440-455` (`finding_zone.unreferenced`) are warnings. Since the patch,
|
||||
`loaded.rs:175-179` turns that into `invalid_sheet` at load, and `pipeline.rs:174-175` refuses to render the draft.
|
||||
The behaviour fails closed and follows the frozen `v1` rule, but a content-only curation step can now take the
|
||||
sheet out of the application. Hint: owner decision. Either keep it (and document it next to the curation workflow)
|
||||
or have `v1` refuse errors only, which would need a new convention version.
|
||||
|
||||
### L5 [LOW] `canonical_json` recursion has no depth bound
|
||||
`fingerprint.rs:129-170` recurses on the typed document. Only the build-time bundle reaches it today. Hint: bound
|
||||
the depth, or reuse the import prescan caps, before any user- or database-supplied sheet goes through
|
||||
`from_bundle` (Step 13).
|
||||
|
||||
### L6 [LOW, context] New test file carries the standard clippy allow
|
||||
`crates/core/tests/r5_6_switch.rs:8` has `#![allow(clippy::disallowed_methods, clippy::unwrap_used, …)]`, the
|
||||
same header as all 40 integration tests. It is test-only, not shipped, and not a security-rule suppression (no
|
||||
`nosemgrep`, `nosec` or `eslint-disable` in the diff). Not blocking.
|
||||
|
||||
Out of scope, filtered: guardrails WARN `SB-POLICY-NOT-OWNER` at `supabase/migrations/20261008110000_anatomical_sheets.sql:1177`
|
||||
(not in the diff, unchanged).
|
||||
|
||||
## Verdict block
|
||||
|
||||
```
|
||||
SECURITY — VERDICT: PASS
|
||||
TOOL: semgrep 1.168.0 — p/security-audit, p/secrets, p/owasp-top-ten
|
||||
SCOPE: 28 files
|
||||
BLOCKING:
|
||||
(none)
|
||||
REPORTED (non-blocking):
|
||||
- [MEDIUM] M1 export grants the trusted alias on the snapshot's unverified reference; export_from_envelope now normalises a mixed envelope; RUST.md §11.20 claims a fingerprint_verified guard absent at this site — crates/core/src/pdf/write/input.rs:205-248, crates/core/src/pdf/write/export.rs:117-136
|
||||
- [LOW] L1 "fingerprint": null read as v0 instead of refused — crates/core/src/domain/sheet/loaded.rs:38-39
|
||||
- [LOW] L2 BundledRef accepts unknown keys, misspelt block loads as v0 — crates/core/src/domain/sheet/loaded.rs:30-40
|
||||
- [LOW] L3 reference and fingerprint_verified public mutable fields — crates/core/src/domain/sheet/loaded.rs:53,66
|
||||
- [LOW] L4 draft-allowed warning makes a v1 bundle unloadable and the generator fail — crates/core/src/domain/sheet/fingerprint.rs:228-231, crates/core/src/domain/sheet/loaded.rs:175-179
|
||||
- [LOW] L5 canonical_json recursion unbounded (trusted input only today) — crates/core/src/domain/sheet/fingerprint.rs:129-170
|
||||
- [LOW] L6 standard clippy allow in new test file, not a security suppression — crates/core/tests/r5_6_switch.rs:8
|
||||
PROOF: semgrep 163 rules on 28 files → 0 findings (0 errors); checklist 9 checks (secrets, SQL concat, unsafe render, authz, error exposure, secret in log, tracked .env, guardrails 0 FAIL / 1 WARN out of diff, new suppressions) → 1 finding (L6); targeted review 5 focus areas → 1 MEDIUM, 5 LOW; worktree runs: cargo r5_6_switch 8, sheet_fingerprint 10, pdf_compare 16, pdf_import 4, curation_draft 20, curation_review 12, vitest r5-6.switch 2, r5-6.n-1 1, all green
|
||||
```
|
||||
@@ -0,0 +1,13 @@
|
||||
# R5.6 rehearsal — fresh verifier (Opus), persisted by the orchestrator (verifier is read-only)
|
||||
|
||||
Contract `.claude/tasks/contracts/2026-10-25-rust-r5-6-rehearsal.md`, patch at 82e2e43, worktree switched.
|
||||
|
||||
VERIFY — VERDICT: ECARTS(3)
|
||||
|
||||
- S1 NOT-MET: export path (`pdf/write/input.rs` assert_exportable :205, keep_the_report_stamp :238) grants the pair from the snapshot's claimed value, never reads `fingerprint_verified`. Probe: v0 sheet-ref (no block) + demo report 27c7 + core build_sheet_snapshot → export succeeds 27c7/27c7 (pre-patch: sheet_mismatch). App store flow cannot reach it (rebase checks the flag). Rest of S1 met (one direction, same sheet, registry only, new report canonical, 9 scenarios tested).
|
||||
- S2 MET (8 Rust files in scope, archive/read.rs and session.rs unchanged, archive check strict, invalid_sheet / sheet_mismatch kept, no n-1 change)
|
||||
- S3 NOT-MET: load conforms; v0 snapshot gets alias privilege at export (same root cause)
|
||||
- S4 MET (2 files differ, value + block v1, document/horse.svg/SQL identical, no oracle/golden changed, original contexts + post-switch twins, O10 77 rows pinned)
|
||||
- S5 MET, S6 MET, S7 MET (main tree inert, patch applies on HEAD)
|
||||
- S8 NOT-MET: alias-security gate fails for the export consumer; everything else green (rust:check RC 0, suites listed, vitest 41/41, rollback report-compare reads the re-export with snapshot kept)
|
||||
- FLOOR clean. Notes: stale `pnpm import:equine` comments (scripts/import-equine.sh:8, CLAUDE.md); verifier overwrote its own scratch probe folder (session scratch only).
|
||||
@@ -346,7 +346,7 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo
|
||||
- [ ] R5.6 rehearsal (owner 2026-10-24 « corrections préalables à la bascule »; contract `.claude/tasks/contracts/2026-10-25-rust-r5-6-rehearsal.md`; isolated worktree, branch inactive)
|
||||
- [x] M1 option 1 (input.rs), directional equivalence + fingerprint_verified, v0/v1 load rules, report-compare status, generator order
|
||||
- [x] original contexts (O7, O10, R2 Zod, R5.1 ledger, TS golden, app goldens) + separate post-switch tests; rust:check + check:all 00:56:22 green on switched state
|
||||
- [ ] gates: security, fresh verifier → checkpoint, STOP (activation on signal)
|
||||
- [x] gates: security PASS (1 MEDIUM, 6 LOW), verifier ECARTS(3) = export grants alias without fingerprint_verified (fix needs snapshot_rules.rs, outside scope) → checkpoint, STOP, owner decision
|
||||
- [ ] R5.6 D-R5 switch (convention, aliases, membership test in gated readers with per-file go, seed regenerated once by the Rust tool, `.prettierignore`, CHANGELOG)
|
||||
- [ ] R5.7 consumer census, domain fixtures moved, packages deleted, xmldom + prettier out of the lockfile, docs, ledger; `pnpm check:all`; merge only on the owner's signal
|
||||
- [ ] DEV hardening (owner 2026-10-24, risk accepted temporarily, not scheduled): Supabase on CLI demo keys + 54321 LAN-open (rootless, UFW allow incoming, no 54321 rule) → own JWT secret/signing keys via env() or narrower 54321 rule before any untrusted device or user (ENVIRONMENTS.md §3.6); never these keys in production; `confirm_sheet_asset_upload` object check before public exposure
|
||||
|
||||
@@ -3539,9 +3539,11 @@ scratchpad; the branch's own state stays inactive (seed `27c7…`, nothing activ
|
||||
the registered historical value of the same sheet, exported against the canonical value, archives a
|
||||
snapshot carrying the report's own stamp; a new report keeps the canonical value. The equivalence is one
|
||||
way (`equivalence(sheet, stamped, current)`: an old stamp against the canonical value, never the
|
||||
reverse) and needs the loaded sheet's `fingerprint_verified` (set only when a `v1` block was checked
|
||||
against the registry and its value recomputed from the document at load, `loaded.rs`
|
||||
`check_reference`; hashing is no longer feature-gated, the wasm module carries `sha2`). `archive/read.rs`
|
||||
reverse). The rebase and `report-compare` also need the loaded sheet's `fingerprint_verified` (set only
|
||||
when a `v1` block was checked against the registry and its value recomputed from the document at load,
|
||||
`loaded.rs` `check_reference`; hashing is no longer feature-gated, the wasm module carries `sha2`). The
|
||||
export does NOT: `input.rs` sees only the snapshot, so it grants the pair on the snapshot's claimed value
|
||||
(gate finding below). `archive/read.rs`
|
||||
stays strictly equal: the M1 envelope holds one value, so no archive check is loosened.
|
||||
|
||||
**v0 and v1.** No block: a historical reference, loaded as before, unverified, no alias privilege, never
|
||||
@@ -3573,3 +3575,18 @@ generator (`import:equine:legacy`) still writes the pre-switch files (`seed.gold
|
||||
|
||||
Not done: the patch is not applied to the branch; `pnpm format` must never run over `.claude/` (it
|
||||
rewrote the append-only audits in the worktree, reverted there).
|
||||
|
||||
Gates on the rehearsal (patch at 82e2e43): security PASS, 1 MEDIUM, 6 LOW
|
||||
(`.claude/audits/2026-10-25-rust-r5-6-rehearsal-security.md`); fresh verifier ECARTS(3)
|
||||
(`.claude/audits/2026-10-25-rust-r5-6-rehearsal-verify.md`), one root cause: the export path has no loaded
|
||||
sheet, so `assert_exportable` and `keep_the_report_stamp` grant the registered pair on the snapshot's
|
||||
claimed value. Probe: a v0 sheet (no block, unverified) with the canonical value, the old demo report and the
|
||||
core's own `build_sheet_snapshot` export with `27c7/27c7` where the pre-patch code answered `sheet_mismatch`.
|
||||
The application cannot reach it (every stored report is rebased first, and the rebase checks the flag), the
|
||||
core's export API can. The fix needs the snapshot builder, outside the approved files: decide the stamp in
|
||||
`domain/archive/snapshot_rules.rs` `build_sheet_snapshot` (it holds the loaded sheet and its flag; called by
|
||||
`ops.rs` `archive.snapshot`) and put `assert_exportable` back to strict equality, so the export never grants
|
||||
an alias. Not applied: awaiting the owner. LOW kept: `"fingerprint": null` and a misspelt block read as v0
|
||||
(no privilege), public mutable `reference`/`fingerprint_verified` fields, a draft-allowed validation warning
|
||||
would make a `v1` bundle unloadable, `canonical_json` recursion unbounded (trusted input today), stale
|
||||
comments on `pnpm import:equine` in `scripts/import-equine.sh` and CLAUDE.md.
|
||||
Reference in new issue
Block a user