docs(docs): R5.6 active, RUST.md 11.22, CHANGELOG, BDR-070, LRN-077, audits, contract clarification
This commit is contained in:
1 parent
9e87016399
commit
b4f54ba000
9 files changed
+250
-1
No files matched your search
@@ -0,0 +1,167 @@
|
||||
# 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
|
||||
@@ -0,0 +1,9 @@
|
||||
# R5.6 active state — fresh verifier (Opus) on 9e87016, persisted by the orchestrator (verifier is read-only)
|
||||
|
||||
VERIFY — VERDICT: ECARTS(1)
|
||||
|
||||
- S1-S6, S8 MET; A1-A5 MET (applied code = verified patch + 4 declared owner adjustments; only sheet-ref.json 03e7f6ab…623b and report-migration-map.json 0e991bc2…e2db changed, value 12d7…74e2, block = registry; document.json, horse.svg, equine_draft.sql identical; no oracle/golden/n-1 change; --check 0 differences; import:equine = Rust, legacy = TS)
|
||||
- S7 NOT-MET: contract still required an inactive branch; activation authorised by the owner inline → settled by the 2026-10-25 activation Clarification of the contract
|
||||
- Probe (direct export API): v0 + canonical → SheetMismatch; mutated document / reference / id → refused; other sheet id → refused; reference set to the alias value after load → strict equality on a caller-declared value (documented trust boundary, no alias privilege); v1 block with aliases [] still recognises (declared list descriptive)
|
||||
- Notes: dangling citations BDR-070 / RUST.md §11.22 (added after); equine_draft.sql header still names packages/anatomy (frozen bytes); scripts/import-equine.sh:3 line long; CHANGELOG added after
|
||||
- FLOOR clean
|
||||
@@ -520,3 +520,7 @@ Status: active. R5.1b + R5.2 done 2026-10-22; documentSha256, seed, report contr
|
||||
## BDR-069 | 2026-10-24 | Refuse three non-canonical v3 report shapes at reader entry
|
||||
|
||||
Decision (owner go): `check_v3_shape` on raw value before `Report::deserialize`: `sheet`, `practitioner` must be objects, `severity` string. At `read_report_document` v3 + `parse_envelope`. Rationale: serde derives accepted positional arrays / one-key enum maps Zod refused → crafted file could swap same-typed fields silently. Alternatives: generic shape guard (draft/shape.rs style) on whole contract (wider, not authorised); `deserialize_with` in contract structs (touches contract). Status: applied d502dfa; v2 + other contracts keep serde leniency (not in go). Owner confirmed fingerprint convention `sha256-rfc8785-validated-v1`, one alias `27c7383c…2660`; R5.6 scope files approved, switch not authorised.
|
||||
|
||||
## BDR-070 | 2026-10-25 | D-R5.6 active: fingerprint `sha256-rfc8785-validated-v1`, registry alias, M1 option 1
|
||||
|
||||
Decision (owner, activation 9e87016): sheet fingerprint = SHA-256(JCS RFC 8785 of R2 typed reading, no integrity error, warnings allowed, depth 128). Equine canonical 12d78872…74e2; old 27c7383c…2660 = sole TRUSTED_ALIASES entry, bound to sheet 503dc301 + content. Alias honoured only via LoadedSheet::recognises_historical_stamp (loader-verified v1 private state + document recomputed at decision + one-way registry pair + same sheet id); equivalence pub(crate). M1 option 1: snapshot of old report keeps its stamp (build_sheet_snapshot); export, archive reader strict. v0 refs (no block) load unverified, no privilege; null/malformed block refused. Rust = sole seed writer, TS legacy until R5.7. Alternatives rejected: A file-bytes (Prettier-bound), C Prettier reproduction; re-stamp at rebase (rewrites reports); export-side alias (M1 defect, no proof). Status: active on feature branch; rollback not transparent for post-switch reports (rebased, nothing lost) → settle before user release.
|
||||
@@ -366,3 +366,8 @@ R5.4: `draft/{labels,changelog,review_report,drawing,overlay,app_review,svg_comp
|
||||
## 2026-10-25 (R5.6 M1 fix)
|
||||
- Cause M1: export sees only snapshot. Fix in build_sheet_snapshot via recognises_historical_stamp (private verified + recompute at use); input.rs strict, unchanged.
|
||||
- null block refused, warnings allowed (is_publishable), canonical depth 128. Fresh worktree final: all gates green, security PASS, verifier CONFORME 8/8. STOP before activation.
|
||||
|
||||
## 2026-10-25 (R5.6 active)
|
||||
- Owner authorised switch. Patch applied (sha = verified worktree), equivalence pub(crate), comments + trust boundary. Seed: fresh --out, 2 files copied (03e7f6ab, 0e991bc2), --check 0 diff.
|
||||
- Switch commit 9e87016: rust:check + check:all green; security PASS LOW; verifier 13/14, ECARTS(1)=S7 pre-activation wording → Clarification.
|
||||
- Rollback measured: new v1 report on pre-switch build → rebased, 0 unresolved, notice shown. BDR-070, LRN-077. STOP, no merge, no R5.7.
|
||||
@@ -555,3 +555,9 @@ Apply: bound = check before the clone/allocation, at every producer (record push
|
||||
Context: R5.5 upload tool. 12 loopback-stub tests green; Claude's run vs real local stack refused by permission layer (transfer tool + service key). Owner ran `pnpm e2e:sheet-assets` by hand → PASS 11/11.
|
||||
Pattern: stub proves tool logic (plan, refusals, retries, no overwrite); only real service proves endpoints, status codes, grants (anon key refused at Storage, not stub). Ship a hand-run e2e script beside stub suite; record each result with its author (simulated by Claude / real by owner), never merge into one "tested".
|
||||
Apply: any tool touching a real service with a privileged key: stub tests in `cargo test`, owner-run e2e script, both results in RUST.md + TODO separately. Owner validated 2026-10-24.
|
||||
|
||||
## LRN-077 | 2026-10-25 | Privilege decision needs proof at the call site holding the evidence
|
||||
|
||||
Context: R5.6 M1. Alias granted at export from snapshot's claimed value; export never saw the loaded sheet. Load-time flag alone also insufficient (pub mutable document/reference).
|
||||
Pattern: put the decision where the evidence object lives (build_sheet_snapshot holds LoadedSheet), keep private verified state set only by the trusted constructor, and recompute the proof at decision time; every other site stays strict equality. Make the raw comparison crate-private so no caller can skip the proof.
|
||||
Apply: any equivalence/allowlist privilege (aliases, migrations, trust marks): one decision method on the verified object, recompute, strict elsewhere, negative tests on the direct API not just app paths.
|
||||
@@ -348,7 +348,8 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo
|
||||
- [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
|
||||
- [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
|
||||
- [x] R5.6 M1 correction + full rehearsal (owner 2026-10-25; snapshot_rules.rs authorised): recognises_historical_stamp, null block refused, warnings allowed, depth 128; fresh worktree r56final: rust:check + check:all 01:53:59 green; security PASS (LOW); verifier CONFORME 8/8 → checkpoint, STOP (activation 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)
|
||||
- [x] R5.6 D-R5 switch ACTIVE (owner go 2026-10-25, commit 9e87016): seed sheet-ref 03e7f6ab + migration map 0e991bc2 only, --check 0 diff, rust:check + check:all green, security PASS LOW, verifier ECARTS(1)=S7 wording → Clarification; BDR-070; rollback not transparent for post-switch reports (settle before user release) → checkpoint, STOP, no merge, no R5.7
|
||||
- [ ] (was) 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
|
||||
- [ ] separate chore (D-R7): form constraints module + PGlite `pg_constraint`/config.toml parity test
|
||||
|
||||
@@ -50,3 +50,9 @@ the two generated artifacts; security audit; fresh verifier.
|
||||
error; the direct export API is tested, not only the application paths. Final state: worktree
|
||||
`/tmp/claude-1000/-home-bchanot-Documents-faunosteo/3571c861-cd6e-4751-a25e-c26da95beb85/scratchpad/r56final`
|
||||
(detached at 8e77e37 + the patch, seed switched by the patch).
|
||||
|
||||
- 2026-10-25 (owner « Autorisation officielle de la bascule R5.6 »): S7 (isolation) is superseded for the activation: the
|
||||
owner authorised the official switch on `feature/rust-r5-pipeline-core` (commit 9e87016) with `equivalence` crate-private,
|
||||
stale comments fixed, the trust boundary documented, and the regeneration of exactly `draft/sheet-ref.json` and
|
||||
`draft/report-migration-map.json` (procedure: fresh temporary `--out`, comparison, the two files only, `--check`). The other
|
||||
S7 parts still hold: no database or Supabase mutation, no oracle regenerated, nothing deleted, no merge.
|
||||
Reference in new issue
Block a user