fix(domain): R5.6 prep gates, strict declared block, patch builds, docs corrected

v1 refuses a non-hex or historical value (NotCanonical); the switch patch now builds
report-compare and refuses unknown block keys; RUST.md 11.19 states the measured
rehearsal (4 + 3 expected failures) instead of a green claim.
This commit is contained in:
bchanot committed 2026-10-24 14:57:44 +02:00
1 parent 3b9a395d43
commit 943a25a98f
10 files changed
+280 -18

No files matched your search

@@ -0,0 +1,168 @@
# Security audit: R5.6 preparation (diff 1f8873d..3b9a395 + the unapplied switch patch)
- date: 2026-10-24 | branch `feature/rust-r5-pipeline-core` | mode: audit (targeted delta), fresh run
- scope: `git diff 1f8873d..HEAD` (12 files: `fingerprint.rs`, its test and oracle, the Node differential,
`Cargo.toml`, `mod.rs`, `rust-check.sh`, RUST.md §11.19, plan, TODO, journal, the patch file) and
`.claude/tasks/plans/r5-6-switch.patch` read as the future change (9 files: `pipeline.rs`, `archive/read.rs`,
`report/rebase.rs`, `sheet/loaded.rs`, `facade.rs`, `pdf/compare/lines.rs`, `pdf/write/input.rs`,
`.prettierignore`, `tests/fingerprint_consumers.rs`)
- owner decisions checked against: convention `sha256-rfc8785-validated-v1`; `TRUSTED_ALIASES` the only alias
authority, bound to sheet and content; `sheet-ref.json` block descriptive, a contradiction refused; an archive's
alias list never trusted
- not done on purpose: no worktree, the patch was not applied (`git apply --check` only: applies cleanly). The
auditor contract forbids mutating code, even a scratch copy; every patch claim below comes from reading.
No service key, no network, no transfer tool, no delete, no code edited. Tree clean before and after.
- run: `cargo test -p faunosteo-core --features fingerprint,pdf-read --locked --offline --test sheet_fingerprint`
with `CARGO_TARGET_DIR` in the session scratchpad → 9 passed. Independent Node recomputation of the draft
(`node -e`, no file written): sha256 of the bytes = `27c7383c…2660` (the alias), raw JCS = `a56e4a24…88a1` =
`oracles/r5/fingerprints.json` `b_rfc8785`.
## Focus 1: can a forged, unknown or foreign-sheet alias make a different document count as the same?
No. `equivalence` (`crates/core/src/domain/sheet/fingerprint.rs:62-79`) returns `TrustedAlias` only when the two
values are exactly the registered `(canonical, alias)` pair, either way round, under the registered `sheet_id`.
There is no transitivity, no prefix or case folding, and `alias_convention` plays no part. Every unknown value is
`Different`, which fails safe: rebase (data kept, items flagged), snapshot dropped, export refused.
At each of the patch's call sites the sheet id is compared before or alongside the equivalence, and the shared id is
the one passed in:
| Site (patch line) | Sheet-id guard | Id passed to `equivalence` |
|---|---|---|
| `report/rebase.rs` (patch L122-126) | `same_sheet &&` | `sheet.reference.sheet_id` |
| `archive/read.rs` `snapshot_matches` (patch L92-100) | `snapshot.sheet_id == report.sheet_id &&` | `report.sheet.sheet_id` |
| `pdf/write/input.rs` `assert_exportable` (patch L248-258) | `sheet_id != … \|\|` | `reference.sheet_id` |
| `pdf/compare/lines.rs` `sheet_line` (patch L212-230) | `sheet_id == … &&` | `reference.sheet_id` |
`check_declared` (`fingerprint.rs:90-108`) can only refuse. `LoadedSheet::from_bundle` drops the declared block
once checked (patch L170-179) and stores no alias. An archive cannot carry an alias list: `SheetSnapshotRef` is
`deny_unknown_fields` (`crates/core/src/domain/archive/snapshot.rs:42`), and nothing reads one.
What the registered pair asserts is proven. The committed `draft/document.json` hashes to the alias by bytes and to
the canonical value through `sheet_fingerprint` (test `the_draft_gives_the_frozen_validated_value`), so both values
are the same bytes. The report stamp and the snapshot stamp are both attacker-controlled strings that could already
be set to the bundled value before the patch. The pair therefore gives a forger no new capability.
## Focus 2: does the patch loosen an archive or envelope check, or hide a real content difference?
`snapshot_matches` and `assert_exportable` are loosened by exactly the registered pair and nothing else. They hide no
content difference, because the pair is one content. The loosening has one side effect on data compatibility,
finding M1 below. It is not a forging vector.
## Focus 3: JCS (`canonical_json`) edge cases
- **Member order:** sorted by `encode_utf16()` vectors (`fingerprint.rs:136-142`), which is RFC 8785's UTF-16
code-unit order. Astral vs BMP is correct (`U+FB33` after `U+1F600`), cross-checked against Node's `<`.
- **Strings:** `"` and `\` escaped, U+0000-U+001F with the short forms, otherwise lowercase `\u00xx`. DEL, `/`,
U+2028 and U+2029 stay verbatim, with no normalisation (`é` ≠ `e`+U+0301). This matches RFC 8785 §3.2.2.2 and
`JSON.stringify`. Lone surrogates are refused at parse (`crates/core/src/domain/js.rs:42-47`), so they get no hash
and are never altered.
- **Numbers:** `js_number` (V8 oracle, 44,322 rows, green). Parsing uses serde_json `float_roundtrip` (workspace
`Cargo.toml`), so it is correctly rounded like `JSON.parse`. A big integer goes `u64 → f64` with nearest-even
rounding, which equals JS (`9007199254740993 → …992`). `JsInt` is f64-backed (`js.rs:94-125`), so there is no
i64 precision divergence. Non-finite values cannot be reached (the parser refuses them).
- **Injectivity:** `canonical_json` is injective on `Value` except `-0`/`0`, both printed `0`. That collision is
spec-conformant, and the core treats the two the same.
- **Duplicate keys:** last wins, as in `JSON.parse` (L2).
- **Unknown keys:** the typed reading is strict (`deny_unknown_fields` on every object, `schema.rs:4`), so no
collision can come from unknown keys (L1 is a documentation error).
- **Defaults:** filling Zod defaults merges only documents with the same meaning.
Net: two documents collide only when the core itself cannot tell them apart. The same document always gives the same
hash in this build and in an RFC 8785 implementation fed the same validated value.
## Focus 4: can the validation before hashing be bypassed?
No, not on any stamping path. `sheet_fingerprint` (`fingerprint.rs:207-221`) runs a strict parse, the strict R2 type,
`validate_sheet_document` with zero issues (warnings included), then `to_value`, JCS and SHA-256. The patch's only
stamping site hashes the exact text written as `document.json` (`pipeline.rs:309` and `:340`, patch L37).
`canonical_json` is public and unvalidated, but no stamping caller uses it. The legacy TypeScript writer
(`import:equine:legacy` until R5.7) still stamps v0 bytes, and the load check does not notice (M2).
## Findings
### M1 [MEDIUM] Envelopes with mixed stamps after the switch lose their snapshot in every pre-switch reader
- After the switch, an old report keeps its `27c7…` stamp on the alias path. The patch's own test asserts this:
`a_report_on_the_historical_value_is_not_rebased_and_keeps_its_stamp`, patch L300; the code is patch L122-126.
- The export snapshot is stamped from the loaded sheet:
`crates/core/src/domain/archive/snapshot_rules.rs:60` → `12d7…`.
- The patched `assert_exportable` accepts the pair and writes it (`crates/core/src/pdf/write/input.rs:204-213`
after the patch). Every old report re-exported after the switch therefore yields `report=27c7…`,
`sheetSnapshot.ref=12d7…`.
- Readers that compare stamps strictly read these envelopes as `snapshot_rejected: sheet_mismatch`:
- the frozen N-1 reader (`packages/core-wasm/tests/n-1/domain/archive/envelope.ts:97-102`);
- today's reader (`crates/core/src/domain/archive/read.rs:116-119`), which is what a `git revert` rollback
restores;
- any deployed pre-switch build.
- Effect: the report is kept, but the archived labels are lost for those readers. Plan §B.12 anticipates only the
rebase of `12d7…` archives, not this.
- It also makes the `TRUSTED_ALIASES` entry permanent. Removing it later (R5.7 cleanup or after) would drop these
snapshots in the current reader too.
- No rehearsal could catch it, because the seed was never switched (L5).
- Fix direction, an owner decision: (a) stamp the snapshot with the report's own stamp when `equivalence` says
`TrustedAlias`; or (b) re-stamp the report with the canonical value on the alias path, which contradicts "stamp
kept"; or (c) accept it, and record "a registry entry is never removed" plus an N-1 test of a re-exported old
report.
### M2 [MEDIUM] The declared-block check is incomplete against "a contradiction must be refused" and plan §B.4/§B.11
Where: patch L148-149 and L170-179 (`crates/core/src/domain/sheet/loaded.rs`), and `fingerprint.rs:90-108`.
- **(a) The check is opt-in.** The block is `#[serde(default)] Option<…>`, and `BundledRef` ignores unknown keys. An
absent or misspelled block (`fingerprints`) skips every check, but plan §B.4 says a reference without a known
convention name is refused.
- **(b) A legacy value under v1 passes.** `check_declared` iterates only the listed aliases.
`document_sha256: "27c7…"` with `{convention: v1, aliases: []}` passes: a sheet declaring v1 while carrying the
v0 value.
- **(c) No hex check.** Nothing checks the bundle's `document_sha256` as 64-hex at load. Plan §B.11 lists "a
malformed hex value" as a tested refusal, and that refusal is absent.
- **(d) Loose block type.** `DeclaredFingerprint` accepts unknown keys.
No false equivalence follows, because `equivalence` never reads the block. The residual risk is convention drift that
goes undetected, for example `import:equine:legacy` rewriting `sheet-ref.json` without the block.
Fix direction: refuse when `document_sha256` is a registered alias of this sheet under a declared v1; apply
`is_sha256_hex` to the ref; put `deny_unknown_fields` on the block type; decide whether absence is refused after the
switch.
### Low findings
| ID | Location | Finding | Direction |
|---|---|---|---|
| L1 | `fingerprint.rs:6-7` | The doc says "unknown keys dropped". The reading is strict (`schema.rs:4`): an unknown key gives `FingerprintError::Shape`. The behaviour is safer than documented. | Correct the doc |
| L2 | `js.rs:42-47`, oracle case 6 | Duplicate member names are accepted with last wins, where RFC 8785 assumes I-JSON. `{"k":1,"k":2}` and `{"k":2}` share a fingerprint. The core and `JSON.parse` read both the same; a first-wins consumer would differ. | Accepted by design; state it in the v1 definition |
| L3 | patch L219-230 (`lines.rs:347-366` after the patch) | The alias branch of `sheet_line` drops the draft/published status that the same-sheet line prints (`lines.rs:351-358`). | Diagnostic only |
| L4 | `fingerprint.rs:112` | `canonical_json` is public and has no validation step. No stamping caller uses it today. | Keep `sheet_fingerprint` the only stamping entry |
| L5 | TODO.md R5.6 prep line; RUST.md §11.19; patch L268 | The evidence conflicts. TODO says "rehearsed (rust:check + check:all 14:32:05 green)"; RUST.md says four suites fail with the generator switched. The rehearsal never regenerated the seed, so the app, N-1 and report-compare suites ran on `27c7…` with the alias paths dormant. The test header cites a non-existent `r5-6-consumers.patch`. | Rerun the gates on a switched seed at the switch |
| L6 | patch `fingerprint_consumers.rs` | No consumer-level test covers a foreign `sheet_id` carrying the registered pair (rebase, archive, export, compare). The four sites are correct by reading; only `equivalence` is unit-tested for it (`sheet_fingerprint.rs`). | Add one case per site |
| L7 | patch L37 | `sheet_fingerprint` parses and validates before the drawings' resource bound (RUST.md §11.19). This is an operator tool on repository input. | Move it after the bound, as planned |
| L8 | `sheet_fingerprint.rs:6`, patch L272 | New `#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]`. All 39 existing test crates carry the same allow, it applies to test targets only, and it is not a security suppression. | Context |
| L9 | `rebase.rs:40` | Pre-existing, kept by the patch: equal stamps skip the rebase without comparing `sheet_id`. The bundle's `document_sha256` is never recomputed at load (wasm has no `fingerprint` feature), so the build is trusted, as with v0. | Context |
Checklist and tool notes:
- Semgrep's packs carry little Rust taint coverage; the manual review above carries this scope.
- The guardrails scanner reports 1 WARN (`SB-POLICY-NOT-OWNER`,
`supabase/migrations/20261008110000_anatomical_sheets.sql:1177`). It is outside this delta and was filtered.
```
SECURITY — VERDICT: PASS
TOOL: semgrep 1.168.0 — p/security-audit, p/secrets, p/owasp-top-ten
SCOPE: 21 files (12 diff files incl. the patch file, 7 patch target files at HEAD, js.rs + json.rs as context); semgrep on 18 (journal.md, TODO.md, RUST.md read and grepped only)
BLOCKING:
(none)
REPORTED (non-blocking):
- [MEDIUM] mixed-stamp envelopes rejected by every pre-switch reader (N-1, rollback, older builds); registry entry becomes permanent — crates/core/src/domain/archive/snapshot_rules.rs:60, patch L122-126 (report/rebase.rs), crates/core/src/pdf/write/input.rs:204-213, packages/core-wasm/tests/n-1/domain/archive/envelope.ts:97-102
- [MEDIUM] declared-block check opt-in, legacy value under v1 accepted, no hex check, block not strict — patch L148-149 + L170-179 (domain/sheet/loaded.rs), crates/core/src/domain/sheet/fingerprint.rs:90-108
- [LOW] doc says unknown keys dropped, reading is strict — crates/core/src/domain/sheet/fingerprint.rs:6-7
- [LOW] duplicate member names accepted (last wins), not I-JSON — crates/core/src/domain/js.rs:42-47
- [LOW] report-compare alias line drops draft/published status — patch L219-230 (pdf/compare/lines.rs)
- [LOW] canonical_json public without validation (no stamping caller) — crates/core/src/domain/sheet/fingerprint.rs:112
- [LOW] rehearsal evidence conflicts, seed never switched, header cites missing r5-6-consumers.patch — .claude/tasks/TODO.md, docs/development/RUST.md §11.19, patch L268
- [LOW] no consumer-level foreign-sheet test of the registered pair — patch tests/fingerprint_consumers.rs
- [LOW] fingerprint computed before the drawings bound — patch L37 (curation/draft/pipeline.rs)
- [LOW] test-crate clippy allow, existing convention, not a security suppression — crates/core/tests/sheet_fingerprint.rs:6, patch L272
- [LOW] pre-existing: rebase on equal sha ignores sheet_id; bundle sha never recomputed at load — crates/core/src/domain/report/rebase.rs:40
PROOF: semgrep 157 rules on 18 files → 0 findings (0 errors); checklist 8 checks → 0 findings in scope (guardrails 0 FAIL / 1 WARN out of scope, filtered); targeted review 4 focus areas → 2 MEDIUM, 9 LOW; cargo test sheet_fingerprint 9 passed; git apply --check clean (not applied)
```
@@ -0,0 +1,15 @@
# R5.6 preparation — fresh verifier (Opus) on 3b9a395, persisted by the orchestrator (verifier is read-only)
VERIFY — VERDICT: ECARTS(2) (criteria P1-P7 from the dispatch brief, no contract file on disk)
- P1 inert: MET (no consumer, seed unchanged, --check 0, 27c7…2660, wasm/app untouched, Cargo.lock unchanged)
- P2 RFC 8785: MET (2 RFC vectors, 44,322 V8 rows, 7 Node cases reproduced; 11 of 24 RFC appendix numbers unpinned)
- P3 validation before hashing, draft = 12d78872…74e2: MET
- P4 registry: MET
- P5 census 147 / 124 / 123: MET (test asserts floors only; non-alias stamp = ffff… in security.snapshot-another-sheet.pdf)
- P6 switch patch: NOT-MET: report-compare build E0063 (BundledRef.fingerprint missing in bin/report_compare.rs); rest checked (five consumers, session.rs through rebase only, alias line in report-compare)
- P7 docs: NOT-MET: "rehearsed green" false with the whole patch (4 curation tests fail, cli build broken); drawings-projection test not fixable by reordering; "four suites" = four tests in two suites
- Outside criteria: switched-seed simulation adds 3 failures (fingerprint_consumers precondition ×2, pdf_import O7 oracle on migrated v2 stamps); alias line drops draft status; patch header cited a missing file; absent block accepted at load
- FLOOR: clean
Orchestrator after: patch fixed (report-compare, strict block, NotCanonical + test, header); RUST.md §11.19, plan §E, TODO corrected; EVAL-031.
+6
View File
@@ -223,3 +223,9 @@ Action: LRN-074, LRN-075; checkpoint R5.4 to owner with decisions (FLOOR clarifi
Method: fresh verifier + security-auditor (opus; pinned Fable agents died on usage credits, re-dispatched), check:all per round; owner ran real-stack e2e by hand.
Anomalies: round 1 verifier ECARTS(4) all real (oversize body → Network+retry, "retried 3×" = 3 attempts, runbook exit codes, FLOOR script never OK); security M1 key on argv in e2e script. Round 2 security 5 LOW (Protocol retried, broadcast DEV addr accepted). Census doc claim "earlier revisions" wrong → corrected before checkpoint.
Action: fixes + negative tests; owner closed R5.5 2026-10-24 (e2e PASS 11/11, owner's run). LRN-076.
## EVAL-031 | 2026-10-24 | R5.6 prep: claimed rehearsal green after extending the patch
Method: fresh verifier applied patch in scratch copy, ran every feature set + switched-seed simulation; security read patch.
Anomalies: docs/TODO said "rehearsed green"; green run covered 5-consumer wiring only, then generator + loaded.rs added without rerun → report-compare E0063, 4 curation tests failing unreported; switched seed never simulated (+3 failures incl. frozen R4 O7). Security M1: alias-path export writes report 27c7 + snapshot 12d7 → pre-switch/N-1 readers drop snapshot.
Action: rerun gate after every patch extension, claim only measured state; patch fixed (build, strict block, NotCanonical); docs corrected; M1 to owner.
+1
View File
@@ -355,3 +355,4 @@ R5.4: `draft/{labels,changelog,review_report,drawing,overlay,app_review,svg_comp
- Owner: R5.5 validated, D-R5.6 decided (compiled registry authority, 5 consumers, Rust sole generator at switch). DEV key risk accepted temporarily, separate hardening task.
- Fingerprint module inert + 9 tests; Rust draft value = frozen 12d7…74e2 first try. Switch as rehearsed patch (green), tree restored, --check 0 diff.
- Rehearsal found: fingerprint before drawings bound (order), loaded.rs/facade.rs outside approved files. STOP before switch.
- Correction: "patch rehearsed green" was false (green run predated generator/load parts; patch broke report-compare build). Verifier caught it; patch fixed, docs corrected. Lesson → EVAL-031.
+2 -2
View File
@@ -341,8 +341,8 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo
- [x] gates: round 1 check:all 03:39:24, security PASS (2 MEDIUM, 6 LOW), verifier ECARTS(2) → positional-parent bypass fixed (1ec9e1b); round 2 check:all 03:51:55, verifier K3/K4 behaviour MET, 2 formal gaps → contract Clarification (owner to confirm) → checkpoint, STOP (no R5.6 without signal)
- [ ] R5.6 preparation (owner 2026-10-24 « arbitrage D-R5.6 »; nothing active)
- [x] `domain/sheet/fingerprint.rs` + `sheet_fingerprint` tests (RFC, V8, Node differential, draft 12d7…, registry, census 123/124 alias)
- [x] switch patch `.claude/tasks/plans/r5-6-switch.patch` rehearsed (rust:check + check:all 14:32:05 green), files restored
- [ ] gates: check:all, security, fresh verifier → checkpoint, STOP (switch on signal)
- [x] switch patch `.claude/tasks/plans/r5-6-switch.patch` (5-consumer wiring rehearsed green rust:check + check:all 14:32:05; whole patch: 4 curation tests fail on current seed, +3 on switched seed, RUST.md §11.19), files restored
- [x] gates on 3b9a395: check:all 14:41:00, security PASS (M1 snapshot stamp → owner, M2 block strictness partly fixed), verifier ECARTS(2) (report-compare build in patch fixed, false "rehearsed green" corrected) → checkpoint, STOP (switch on signal)
- [ ] 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
@@ -89,7 +89,7 @@ fingerprint) is later. No merge, no release, no deploy.
Decided: convention confirmed; compiled registry the only authority, bound to sheet + content; five consumers
(adds `pdf/compare/lines.rs`); Rust the only generator, `pnpm import:equine` → Rust, TypeScript kept as
`import:equine:legacy` until R5.7; no visible change, no migration message. Prepared (RUST.md §11.19):
module + tests committed inert; the switch as `.claude/tasks/plans/r5-6-switch.patch`, rehearsed green.
module + tests committed inert; the switch as `.claude/tasks/plans/r5-6-switch.patch` (applies cleanly; on the current seed 4 `curation` tests fail as expected, with the seed switched 3 more: RUST.md §11.19; the earlier "rehearsed green" covered the five consumers only).
Still to decide at the switch signal:
1. `loaded.rs` + `facade.rs` (sheet load refuses a contradicting block): outside the five approved files,
@@ -97,7 +97,10 @@ Still to decide at the switch signal:
2. The two `curation_draft` cases move to a declared rule for `sheet-ref.json` and `report-migration-map.json`
(fingerprint field and block only), the R5.1 oracles untouched.
Switch procedure (on the signal): apply the patch; move the fingerprint after the drawings bound; declared
3. M1 (security): the export's snapshot reference on an alias match: the report's own stamp (recommended), re-stamp at rebase, or accept with an N-1 test.
4. M2 remainder: refuse a `sheet-ref.json` without a fingerprint block after the switch (every test sheet then needs one).
Switch procedure (on the signal): apply the patch; move the fingerprint after the drawings bound and keep the drawings-bound fixture valid; declared rules for the O7 oracle and the switched-seed preconditions; declared
rule in `curation_draft`; `pnpm import:equine` → `scripts/import-equine.sh`, TS as `import:equine:legacy`;
`import-equine --out` into an empty folder, diff reviewed (only the two files of §11.19), copied over `draft/`;
`--check` 0 differences; `pnpm rust:check`, `pnpm check:all`, security, fresh verifier; owner device check
+28 -6
View File
@@ -9,6 +9,27 @@ index a9140e4..aaeef54 100644
+# Written by the Rust pipeline (`pnpm r5:import-equine`, R5.6): byte-exact, never reformatted.
+supabase/seed/anatomical-sheets/equine/legacy-import/
+supabase/seed/anatomical-sheets/equine/draft/
diff --git a/crates/core/src/bin/report_compare.rs b/crates/core/src/bin/report_compare.rs
index 59cf060..91b34ef 100644
--- a/crates/core/src/bin/report_compare.rs
+++ b/crates/core/src/bin/report_compare.rs
@@ -37,6 +37,8 @@ struct SeedRef {
document_sha256: String,
schema_version: f64,
species_id: String,
+ #[serde(default)]
+ fingerprint: Option<faunosteo_core::domain::sheet::loaded::DeclaredFingerprint>,
}
fn seed_json<T: for<'de> Deserialize<'de>>(name: &str) -> Result<T, String> {
@@ -58,6 +60,7 @@ fn load_sheet() -> Result<LoadedSheet, String> {
document_sha256: reference.document_sha256,
schema_version,
species_id: reference.species_id,
+ fingerprint: reference.fingerprint,
},
document: seed_json("document.json")?,
migration_map: seed_json("report-migration-map.json")?,
diff --git a/crates/core/src/curation/draft/pipeline.rs b/crates/core/src/curation/draft/pipeline.rs
index 19126aa..12bcaf5 100644
--- a/crates/core/src/curation/draft/pipeline.rs
@@ -129,7 +150,7 @@ index 9281642..b5012be 100644
report: report.clone(),
unresolved_zones: 0,
diff --git a/crates/core/src/domain/sheet/loaded.rs b/crates/core/src/domain/sheet/loaded.rs
index 4065978..aa88299 100644
index 4065978..e6fd44d 100644
--- a/crates/core/src/domain/sheet/loaded.rs
+++ b/crates/core/src/domain/sheet/loaded.rs
@@ -2,6 +2,7 @@
@@ -140,7 +161,7 @@ index 4065978..aa88299 100644
use std::collections::HashMap;
use serde::Deserialize;
@@ -33,6 +34,15 @@ pub struct BundledRef {
@@ -33,6 +34,16 @@ pub struct BundledRef {
pub document_sha256: String,
pub schema_version: JsInt,
pub species_id: String,
@@ -150,13 +171,14 @@ index 4065978..aa88299 100644
+}
+
+#[derive(Debug, Clone, Deserialize)]
+#[serde(deny_unknown_fields)]
+pub struct DeclaredFingerprint {
+ pub convention: String,
+ pub aliases: Vec<String>,
}
/// A loaded, indexed sheet.
@@ -76,6 +86,8 @@ pub enum LoadError {
@@ -76,6 +87,8 @@ pub enum LoadError {
Shape(serde_json::Error),
/// The document has no main view.
NoMainView,
@@ -165,7 +187,7 @@ index 4065978..aa88299 100644
}
impl From<serde_json::Error> for LoadError {
@@ -102,6 +114,15 @@ impl LoadedSheet {
@@ -102,6 +115,15 @@ impl LoadedSheet {
.map(|(id, text)| (id.clone(), read_drawing(text)))
.collect();
let r = data.reference;
@@ -261,11 +283,11 @@ index 120249a..6a4bfe5 100644
if report.observations.len() > MAX_OBSERVATIONS {
diff --git a/crates/core/tests/fingerprint_consumers.rs b/crates/core/tests/fingerprint_consumers.rs
new file mode 100644
index 0000000..bda5a2e
index 0000000..39a5775
--- /dev/null
+++ b/crates/core/tests/fingerprint_consumers.rs
@@ -0,0 +1,69 @@
+//! R5.6 switch rehearsal (part of `.claude/tasks/plans/r5-6-consumers.patch`, not committed
+//! R5.6 switch rehearsal (part of `.claude/tasks/plans/r5-6-switch.patch`, not committed
+//! active): with the loaded sheet stamped with the canonical `v1` value, a report or an archive
+//! stamped with the registered historical value is the same document (no rebase, archive kept);
+//! a real content change, a forged value or another sheet still differ.
+11 -2
View File
@@ -3,8 +3,8 @@
//! generated file uses this module until the owner's switch signal (RUST.md §11.19).
//!
//! The value is the SHA-256 of the RFC 8785 (JCS) text of the validated document: the strict
//! typed reading of the R2 contract (`AnatomicalSheetDocument`, Zod's defaults filled, unknown
//! keys dropped) with zero integrity issue, serialised back. JCS: members sorted recursively by
//! typed reading of the R2 contract (`AnatomicalSheetDocument`, Zod's defaults filled, the
//! strict shape refusing unknown keys) with zero integrity issue, serialised back. JCS: members sorted recursively by
//! the UTF-16 code units of their names, numbers as ECMAScript `Number::toString`, strings with
//! the `JSON.stringify` escape set and every other character kept as is (no Unicode
//! normalisation), no whitespace, UTF-8. `v1` freezes these rules and the validation.
@@ -82,6 +82,8 @@ pub enum AliasRefusal {
UnknownConvention(String),
/// A declared alias the registry does not bind to this sheet and canonical value.
Untrusted(String),
/// The value declared under `v1` is not a 64-hex value, or is itself a historical alias.
NotCanonical(String),
}
/// Checks what a `sheet-ref.json` declares (descriptive only): the convention must be `v1` and
@@ -96,6 +98,13 @@ pub fn check_declared(
if convention != FINGERPRINT_CONVENTION {
return Err(AliasRefusal::UnknownConvention(convention.to_owned()));
}
let hex = canonical.len() == 64
&& canonical
.bytes()
.all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'f'));
if !hex || TRUSTED_ALIASES.iter().any(|entry| entry.alias == canonical) {
return Err(AliasRefusal::NotCanonical(canonical.to_owned()));
}
for alias in aliases {
let trusted = TRUSTED_ALIASES.iter().any(|entry| {
entry.sheet_id == sheet_id && entry.canonical == canonical && entry.alias == alias
+14
View File
@@ -254,3 +254,17 @@ fn historical_archives_open_as_the_same_document_only_through_the_registered_pai
);
assert!(same > 30, "{same} of {}", found.len());
}
#[test]
fn v1_never_carries_the_historical_value_or_a_malformed_one() {
assert_eq!(
check_declared(SHEET, ALIAS, FINGERPRINT_CONVENTION, &[]),
Err(AliasRefusal::NotCanonical(ALIAS.into()))
);
for bad in ["", "12d7", &"g".repeat(64), &CANONICAL.to_uppercase()] {
assert!(
check_declared(SHEET, bad, FINGERPRINT_CONVENTION, &[]).is_err(),
"{bad}"
);
}
}
+30 -6
View File
@@ -3486,8 +3486,14 @@ needs no own change, it goes through the rebase), the generator stamping `sheet_
descriptive block, the sheet load refusing a block that contradicts the registry (`loaded.rs`, `facade.rs`:
`invalid_sheet`), `.prettierignore` on `legacy-import/` and `draft/`, and the rehearsal suite
`fingerprint_consumers` (3: alias not rebased and stamp kept, real change and forged value rebased, archive pair
kept and forged pair rejected). Rehearsal with the patch applied: `pnpm rust:check` green, `pnpm check:all` green
14:32:05, then the files restored.
kept and forged pair rejected). Rehearsal, corrected by the fresh verifier: `pnpm rust:check` and `pnpm check:all`
(14:32:05) were green with the five consumers wired only, before the generator, load and `report-compare` parts
were added. With the whole patch on the current seed: the `cli`, `fingerprint` and default suites are green, 4 tests
of `curation` fail (below). With the seed switched as well (verifier's simulation in a scratch copy), 3 more fail:
the 2 `fingerprint_consumers` cases whose precondition reads the seed as `27c7…`, and `pdf_import`
`o7_locate_and_read_match_the_typescript`, whose frozen R4 oracle records the stamp of migrated v2 reports
(`scan.report-v2-{full,minimal}.pdf`), which follows the migration map to `12d7…`. Neither suite has run
end to end on a switched seed yet.
**Seed at the switch (measured with the patch, written to a scratch folder, never to the seed):**
@@ -3497,9 +3503,27 @@ kept and forged pair rejected). Rehearsal with the patch applied: `pnpm rust:che
| `draft/report-migration-map.json` | sha256 `4139c51d…fce9`, `sheet.documentSha256` `27c7…` | sha256 `0e991bc2…2db`, `12d7…` | a migrated v2 report is stamped with the current value | same | `git revert` |
| the 16 other files | unchanged | unchanged (`document.json`, `horse.svg`, `equine_draft.sql` compared byte for byte) | no content change | `--check` | n/a |
Found by the rehearsal, to settle in the switch: four suites fail with the generator switched. Two expect it
To settle in the switch: four tests in two suites fail with the generator switched. Two expect it
(`curation_draft`: the draft files byte for byte against the TypeScript ledger, and the historical fingerprint
test): at the switch they compare the two files under a declared rule (the fingerprint field and block only),
the oracles untouched. Two are an order defect of the rehearsal (`curation_review`, drawings bound tests): the
fingerprint validates the document before the drawings' resource bound applies; the switch computes it after
that bound.
the oracles untouched. Two in `curation_review`: `review_drawings_past_their_bound_are_refused_before_rendering`
needs the fingerprint after the drawings bound (order); `the_drawings_projection_bounds_what_is_written` builds a
draft with every annotation removed, an invalid document that now has no fingerprint, so its fixture has to stay
valid (reordering does not fix it). The O7 oracle and the switched-seed preconditions take a declared rule too.
Gates on 3b9a395: `pnpm check:all` green 14:41:00; security PASS, 2 MEDIUM, 9 LOW
(`.claude/audits/2026-10-24-rust-r5-6-prep-security.md`); fresh verifier ECARTS(2)
(`.claude/audits/2026-10-24-rust-r5-6-prep-verify.md`): the patch broke the `report-compare` build (fixed in the
patch) and these docs claimed a green rehearsal (corrected above). Fixed after: the declared block is strict
(unknown keys refused), and `v1` refuses a value that is not 64 lowercase hex or that is itself a registered
alias (`AliasRefusal::NotCanonical`, test). Open for the owner, MEDIUM M1: on the alias path the report keeps
`27c7…` while a new export's snapshot takes `12d7…` from the loaded sheet; the frozen N-1 reader, a rollback build
and any pre-switch build compare the two strictly and would drop that envelope's snapshot (`sheet_mismatch`; the
report is kept, the archived labels lost), and the registry entry could then never be removed. Remedies: the
export writes the snapshot reference with the report's own stamp on an alias match (recommended: every reader
then sees one value, nothing rewritten), or the report is re-stamped at the rebase, or accepted with an N-1 test.
Open, M2 remainder: a `sheet-ref.json` without a block still loads unchecked (pre-switch bundles and the test
sheets carry none); refusing it at the switch means giving every test sheet a block. Also: the census asserts floors
(over 50 attachments, over 30 alias stamps), not the exact 147/124/123; 11 of the RFC's 24 appendix numbers are not
in the V8 oracle (they print right in a probe, unpinned); the `report-compare` alias line drops the draft/published
status the plain line shows.