fix(domain): sheet.check reads its document without an intermediate copy; RUST.md states the copy behaviour exactly

Second security pass on e49009e: PASS with two LOW items, both applied.
Module 1,044,559 B raw / 340,154 B gzip; core 135, core-wasm 25, app 313.
This commit is contained in:
bchanot committed 2026-10-14 01:07:17 +02:00
1 parent 651f1fef13
commit 36316cf67f
3 files changed
+12 -8

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ Versions follow [Semantic Versioning](https://semver.org/).
### Changed (Rust R2, domain core, 2026-10-14)
- **The application's domain rules run in Rust** (`crates/core`, through the wasm facade and `@faunosteo/core-wasm`): sheet, report and archive contracts with the Zod semantics reproduced, the 21 sheet integrity rules and the publish check, the sheet index, the v2 → v3 migration, the rebase on the loaded sheet, the sheet snapshot, the layered archive reading, the editor's click chain and reducers, the findings and vertebra rules, report creation and the observation list operations. Consumers switched: the editor, the pickers, the store, the draft restore, the PDF import (after the engine's byte scan) and export (snapshot), the Supabase publish gate (fails closed). The module (341 KB gzip) loads only on the sheet pages; sign-in, the `/app` space and Home never request it. Without `'wasm-unsafe-eval'` in the CSP the editor shows a degraded notice with a retry and leaves the session's draft untouched (DEPLOY.md: set the keyword before deploying an R2 image; R2 images are never built on the VPS).
- **The application's domain rules run in Rust** (`crates/core`, through the wasm facade and `@faunosteo/core-wasm`): sheet, report and archive contracts with the Zod semantics reproduced, the 21 sheet integrity rules and the publish check, the sheet index, the v2 → v3 migration, the rebase on the loaded sheet, the sheet snapshot, the layered archive reading, the editor's click chain and reducers, the findings and vertebra rules, report creation and the observation list operations. Consumers switched: the editor, the pickers, the store, the draft restore, the PDF import (after the engine's byte scan) and export (snapshot), the Supabase publish gate (fails closed). The module (340 KB gzip) loads only on the sheet pages; sign-in, the `/app` space and Home never request it. Without `'wasm-unsafe-eval'` in the CSP the editor shows a degraded notice with a retry and leaves the session's draft untouched (DEPLOY.md: set the keyword before deploying an R2 image; R2 images are never built on the VPS).
- **Session data never dropped silently**: an unreadable draft or archive is set aside under `osteo:quarantine:*` with a notice; a draft rebased with unresolved items keeps its raw text.
- Behaviour differences, declared in `docs/development/RUST.md` §8.7: drafts and attachments written in contract order (values unchanged, the previous build reads them, D-R11); a lone UTF-16 surrogate escape reads as U+FFFD (L1, to confirm); typed errors on inputs the interface never produced.
- Proofs: contracts byte-equal to the Zod output on the reference documents, the three archive envelopes frozen before the switch and deep-equal after, 924 cases and verdicts frozen from the TypeScript, permanent N-1 reader test, generated pgTAP conformance file (real stack 446/446), CSP proof on the real image. No interface, archive format, database or graphic change; release 0.2.0 untouched.
+2 -1
View File
@@ -11,6 +11,7 @@ use crate::domain::archive::build_sheet_snapshot;
use crate::domain::editor::{
self, EditorError, LeafClick, MoveDirection, NewReportDraft, NewReportStamp, VertebraAction,
};
use crate::domain::js::parse_json;
use crate::domain::report::{LateralSide, Observation, Report, SheetRef, Vertebra};
use crate::domain::session::{self, ImportFailure, RestoreFailure};
use crate::domain::sheet::{LoadedSheet, SheetIndexData, check_sheet_document};
@@ -104,7 +105,7 @@ pub fn free(op: &str, input: &str) -> Option<Outcome> {
}
fn sheet_check(input: &str) -> Outcome {
let document: Value = parse_input(input)?;
let document = parse_json(input).map_err(|error| Failure::new("invalid_json", error))?;
let check =
check_sheet_document(document).map_err(|error| Failure::new("invalid_shape", error))?;
to_value(&check)
+9 -6
View File
@@ -573,7 +573,7 @@ Closed failure kinds: `invalid_json`, `invalid_shape`, `unknown_op`,
| Measure | Value |
|---|---|
| shipped module | 1,046,498 B raw (native), **340,929 B gzip -9** (budget 600 KB); before the by-reference deserialisation of the security follow-up: 1,180,153 B raw / 372,275 B served by the image |
| shipped module | 1,044,559 B raw (native), **340,154 B gzip -9** (budget 600 KB); before the by-reference deserialisation of the security follow-up: 1,180,153 B raw / 372,275 B served by the image |
| glue | 10,171 B |
| load (compile + instantiate) | 6 to 8 ms |
| sheet handle + index data (bundle 0.5 MB) | 22 to 27 ms (TypeScript parse + index on the same input: 12 to 15 ms) |
@@ -585,10 +585,13 @@ Closed failure kinds: `invalid_json`, `invalid_shape`, `unknown_op`,
| app image | 104 MB (wasm stage: the Rust toolchain stays in the builder) |
Pages without the core load nothing more than before R2; the sheet pages
fetch about 351 KB more (glue + gzip module) once per session. Every JSON
input is deserialised by reference (`T::deserialize(&Value)`), never through
a copy of the value: a large attachment is not duplicated in linear memory,
and one deserialiser instead of two keeps the module smaller.
fetch about 351 KB more (glue + gzip module) once per session. JSON inputs
are deserialised by reference (`T::deserialize(&Value)`): the imported
attachment is never copied as a whole value (its strings are copied once
into the typed contract), and one deserialiser instead of two keeps the
module smaller. Operation inputs (`parse_input`) keep the parsed value alive
while their strings are copied out: a transient, linear peak on inputs the
application itself builds.
### 8.7 Behaviour differences (declared)
@@ -626,7 +629,7 @@ and one deserialiser instead of two keeps the module smaller.
- The CSP proof runs Chromium only (no Firefox or WebKit build on this
machine): the owner's manual run of the image on other browsers and the
phone covers Safari and Firefox.
- The module grows with each phase (341 KB of the 600 KB budget at R2; the
- The module grows with each phase (340 KB of the 600 KB budget at R2; the
`url` crate's IDNA tables are part of it): R3/R4 must keep measuring.
- The quarantine slots (`osteo:quarantine:*`) keep verbatim copies of drafts
(practitioner, owner and animal data) until the tab closes, the same