fix(anatomy): R5.4 review drawings bounded per annotation, report tables summed, docs counts
This commit is contained in:
1 parent
29eb499539
commit
411e1058c0
9 files changed
+271
-36
No files matched your search
@@ -0,0 +1,125 @@
|
||||
SECURITY — VERDICT: BLOCK(1)
|
||||
TOOL: semgrep 1.168.0 — p/security-audit, p/secrets, p/owasp-top-ten
|
||||
SCOPE: 29 files
|
||||
BLOCKING:
|
||||
1. [HIGH] review-drawings-amplification — crates/core/src/curation/draft/pipeline.rs:209 (bound at :205, projection at :211; amplifier reached through crates/core/src/curation/draft/app_review.rs:33 → crates/core/src/anatomy/layer.rs:108-118) — the 64 MiB review-drawing bound projects only the cleaned drawing repeated per view; every unnamed detail trigger copies the opened view's fr and en names four times into review/app-<view>.svg, so T triggers × a view name of S bytes write 4·T·S bytes unchecked: a 485,140-byte changes.json produced a 131,713,082-byte app-main.svg (no refusal), a 1,202,892-byte changes.json made the run abort on a 1 GiB allocation under a 3 GB cap, about 44 GiB at the 16 MiB read cap — hint: project each view's layer bytes before render_layer (per annotation: fixed overhead + geometry text + 4 × the name it carries, the opened view's names for an unnamed trigger) and refuse past MAX_REVIEW_DRAWINGS_BYTES together with the cleaned-drawing projection; add a test with unnamed triggers opening a long-named view; correct the RUST.md §11.14 row
|
||||
REPORTED (non-blocking):
|
||||
- [LOW] report-tables-bound-per-table — crates/core/src/curation/markdown.rs:162 (and changelog.rs:118)
|
||||
- [LOW] report-guard-stale-doc — crates/core/src/curation/report_guard.rs:14
|
||||
- [LOW] record-weight-omits-position — crates/core/src/curation/draft/records.rs:187
|
||||
- [LOW] test-lint-relaxation (convention, not a scanner suppression) — crates/core/tests/curation_markdown.rs:6, crates/core/tests/curation_review.rs:6
|
||||
PROOF: semgrep 162 rules on 29 files → 0 findings; checklist 12 checks → 5 findings
|
||||
|
||||
## Scope and method
|
||||
|
||||
Range `c6e0d85..HEAD` (HEAD 29eb499), paths `crates/core`, `packages/anatomy/tests`,
|
||||
`docs/development/RUST.md`: 29 added or modified files, all scanned by semgrep (162 rules
|
||||
loaded from the three pinned packs, 0 results, 0 errors).
|
||||
|
||||
Checklist, in order: hardcoded secrets (none), SQL by string building (none in the diff; the
|
||||
seed SQL writer is unchanged R5.3 code), unsanitised render (Markdown reports and SVG drawings,
|
||||
below), sensitive endpoint authz (none: a local CLI and a library), internals surfaced to a user
|
||||
(CLI stderr on a developer machine, not applicable), secrets in logs (none), tracked `.env` or
|
||||
credential (only `.env.example`, outside the diff), guardrails scanner (`--domain api,supabase`:
|
||||
0 FAIL, 1 WARN in `supabase/migrations/20261008110000_anatomical_sheets.sql:1177`, outside the
|
||||
diff, dropped), new suppressions (two test headers, LOW below), then the brief's threat model:
|
||||
Markdown parity against Prettier 3.8.3, resource bounds (records, tables, drawings), CLI file
|
||||
system confinement, SVG well-formedness.
|
||||
|
||||
Probes live in the session scratchpad, never in the repository:
|
||||
`/tmp/claude-1000/-home-bchanot-Documents-faunosteo/9b0edf59-ccd2-4662-b90c-e473dd78028e/scratchpad/probe`
|
||||
(a crate with a path dependency on `crates/core`, feature `curation`; `src/main.rs` wraps
|
||||
`report_guard::format_report`, `src/bin/amplify.rs` runs the draft pipeline in memory on the
|
||||
committed seed plus one extra change), `.../scratchpad/scripts/fmt.mjs` (the repository's
|
||||
Prettier 3.8.3 with the options of `packages/anatomy/src/format.ts`) and
|
||||
`.../scratchpad/scripts/{gen,gen2,widths,strong,diff}.py` (case generators and the
|
||||
differential). Nothing was written to the seed or any tracked file.
|
||||
|
||||
## Finding 1 (HIGH): the review-drawing bound does not cover the markers
|
||||
|
||||
`pipeline::review_drawings` refuses before rendering when
|
||||
`cleaned_svg.len() * 2 * views > MAX_REVIEW_DRAWINGS_BYTES` (64 MiB). RUST.md §11.14 states the
|
||||
guarantee as "review drawings past 64 MiB in all, projected before any is rendered … refused
|
||||
before rendering". The projection counts the cleaned drawing only. The application drawing of a
|
||||
view (`app_review::render_app_review_drawing` → `anatomy::layer::render_layer`) writes, for each
|
||||
detail trigger without a name of its own, the opened view's French and English names into
|
||||
`data-anno-name-fr`, `data-anno-name-en` and the `<title>` text `fr / en`: four copies of the
|
||||
view name per trigger. Nothing caps a view name (the sheet contract has no label length) or the
|
||||
number of triggers opening one view (integrity only requires the trigger to sit in the opened
|
||||
view's parent).
|
||||
|
||||
An authored change of one `set view:head name {fr: S bytes, en: S bytes}` and T `add document
|
||||
annotations` of unnamed detail triggers in `main` opening `head` passes the applier, the records
|
||||
bound, the 200,000-value document bound and the integrity gate, then writes about 4·T·S bytes in
|
||||
`review/app-main.svg`:
|
||||
|
||||
| S (per language) | T | changes.json | result |
|
||||
|---|---|---|---|
|
||||
| 1,024 | 10 | 166,322 B | 2.87 MB in all (baseline) |
|
||||
| 32,768 | 1,000 | 485,140 B | `review/app-main.svg` 131,713,082 B written, no refusal, peak RSS 429 MB |
|
||||
| 262,144 | 2,000 | 1,202,892 B | `memory allocation of 1073741824 bytes failed`, SIGABRT under `ulimit -v 3000000` (peak RSS 2.65 GB) |
|
||||
|
||||
At the read cap the records bound allows about S = 2 MiB and T = 5,600 (the set records 4·S
|
||||
units, each add about 1,500), so the tool would try to build about 44 GiB from a 5.4 MB
|
||||
changeset. `pnpm r5:import-equine --check` and `--out` both build every file before comparing or
|
||||
writing, so either mode dies on such a changeset. The TypeScript has the same amplification;
|
||||
the defect is that the port's declared bound, the control the round-8 fix introduced for this
|
||||
class, does not hold.
|
||||
|
||||
Reproduce: `cd .../scratchpad && (ulimit -v 4000000; ./probe/target/release/amplify 32768 1000)`.
|
||||
|
||||
Fix direction: project each view's drawing bytes before `render_layer`: the cleaned drawing,
|
||||
plus, per annotation of the view, a fixed overhead, its geometry text and four times the name
|
||||
bytes it carries (own name, or the opened view's names through `localized_names` for an
|
||||
unnamed trigger), plus the overlay's markers; refuse the sum past the bound. Freeze it with a
|
||||
test of unnamed triggers opening a long-named view, and restate the §11.14 row.
|
||||
|
||||
## LOW findings
|
||||
|
||||
- `markdown.rs:162` / `changelog.rs:118`: `MAX_TABLE_COLUMNS_TOTAL` bounds each table, not the
|
||||
report. The three level tables of the CHANGELOG can each approach 32 Mi columns: a synthetic
|
||||
raw report with three 6,000-row tables and one 5,300-byte cell each was admitted and aligned
|
||||
into 97,356,707 bytes (peak RSS 272 MB). Reaching it through the applier takes about 18,000
|
||||
records, at the edge of the 16 Mi-unit records bound. Bounded, consistent with the RUST.md
|
||||
wording ("an aligned report table"); a whole-report bound would make the worst case explicit.
|
||||
- `report_guard.rs:14-17`: the module doc says a code span admits "anything but a carriage
|
||||
return or a tab"; `generated_code` (`:186-193`) admits only `[A-Za-z0-9_:/. -]`, as RUST.md
|
||||
states. The code is the stricter one; the doc of the control is stale.
|
||||
- `records.rs:187-197`: `op_weight` does not charge the `position` anchor of an `add` or a
|
||||
`move` (`{"after": …}` / `{"before": …}`), which each record clones. One record per such op
|
||||
and the anchor must name an existing sibling, so the total stays under the changeset size:
|
||||
no amplification, the weight model is only incomplete.
|
||||
- `tests/curation_markdown.rs:6`, `tests/curation_review.rs:6`:
|
||||
`#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]` in two new
|
||||
integration-test files. The same header is on every test file of the crate, and `clippy.toml`
|
||||
says "Tests and the worker binary allow these lints locally where they own I/O". The library's
|
||||
I/O and clock ban stays enforced in `src/`. This is not a scanner-finding suppression, so it
|
||||
does not block.
|
||||
|
||||
## What held
|
||||
|
||||
- Markdown guard against Prettier 3.8.3: 189,394 generated reports in the templates of
|
||||
`changelog.rs` and `review_report.rs` (list items, bibliography, vet-flag lines, eight-column
|
||||
rows with `cell()` escaping). The cases cover random token mixes, admitted-only mixes, every
|
||||
code point from U+00A0 to U+33FF plus one in three up to U+2FFFF, in a table cell and in a
|
||||
list line, and `**word**` over the same letters. Result: 99,447 admitted, every admitted one
|
||||
byte for byte equal to Prettier, 0 silent differences. Structure forging (headings, list
|
||||
items, links, HTML, autolinks, references, code spans from authored text) is refused at the
|
||||
guard or at `assert_single_line` / `assert_authored`.
|
||||
- Records: every producer goes through `charge` (`ops.rs`, `rename.rs`, `apply.rs`
|
||||
marking). Raw report rows are bounded with the records. Aligned tables are refused before
|
||||
they are built. The guard and the aligner are linear per line.
|
||||
- SVG: element and attribute names are the generator's. Values and texts are escaped (`&`,
|
||||
`<`, `>`, `"`, tab, LF, CR). `first_unwritable` refuses non-XML-1.0 code points and CR. No
|
||||
author text can open a script or an href.
|
||||
- `--check`: byte identity, and the tree fallback only for `review/app-*` with the declared rule,
|
||||
after the committed file rebuilds from its tree. The committed drawing goes through the core
|
||||
reader first (depth cap), and `roxmltree` keeps its DTD refusal. Reads are confined to the
|
||||
canonical seed and capped at 16 MiB. A symlinked folder is never walked.
|
||||
- `--out`: no `..`, the parent is canonicalised, the final symlink is refused, the destination
|
||||
must be absent or empty, and it is refused inside the seed by path and by (dev, inode) over
|
||||
the whole seed tree. Writes use `create_dir` / `create_new`, never truncate, never delete.
|
||||
The check-to-write swap is the single-user residual already declared (§11.13).
|
||||
- Oracle generators (`packages/anatomy/tests/r5.*.test.ts`) write only under
|
||||
`MAKE_R5_ORACLES=1`, into `crates/core/tests/oracles/r5`. The Rust tests write only under
|
||||
the target folder.
|
||||
@@ -70,6 +70,12 @@ Fresh verifier and security on the fixed commit: below.
|
||||
- Security (`.claude/audits/2026-10-23-rust-r5-review-security-9.md`): HIGH records weight undercount: the change's reference ids at one unit per byte while each cloned id costs ≈56 bytes (200,000 one-character ids × 100 set ops: 948 MB before the bound; 16.4 MB file: 1.67 GB). MEDIUM `parse_changeset` ≈65× the input (1.075 GB at 16.4 MB; R5.3, outside the diff); MEDIUM guardrails WARN in a migration outside the diff; LOW test allows. Not covered: markers and labels bound of the drawings.
|
||||
- Fixed: every cloned string (texts, ids, op strings, object keys) weighs 64 + its bytes (`records::text_weight`; equine 1,965,944, bound 8.5× above); ids case added to `the_records_bound_holds_inside_one_op_and_the_marking`; parse amplification declared in §11.15 (owner decision on a lower input cap); RUST.md row updated.
|
||||
|
||||
## Round 10
|
||||
## Round 10 on 29eb499: verifier C1 to C8 MET, C9 NOT-MET (stale counts) + 10 FLOOR (audit prose), security BLOCK(1); `pnpm check:all` green 15:38:01
|
||||
|
||||
- Verifier: 47,470 TS-vs-Rust Markdown cases 0 silent (the unguarded aligner gave 34 on the same inputs), 117 SVG label cases bytes or declared rule. C9: RUST.md counts stale (review tests 9 → 10, suites, draft lines 4,385 → 4,532) and the `report_guard.rs` header ("anything but CR or tab" inside code spans). Info: "`<` before a letter" means an ASCII letter; number cells 24 bytes where a JS number prints 25.
|
||||
- Security (`.claude/audits/2026-10-23-rust-r5-review-security-10.md`): HIGH the drawings bound counted the cleaned drawing only: an unnamed trigger copies the opened view's names four times (485 KB changeset → 131 MB `app-main.svg`; 1.2 MB → abort at 3 GB). LOW tables bound per table (three level tables ≈97 MB together); LOW stale `report_guard.rs` header; LOW add/move position anchor not charged; LOW test allows.
|
||||
- Fixed: drawings projected as an upper bound per annotation (`pipeline::review_drawings_bytes`: 1,024 + 24 × (JSON text + longest view name) per annotation of the view, overlay's two documents and the app drawing; equine 1,390,428), test `unnamed_triggers_repeating_a_long_view_name_are_refused_before_rendering`; CHANGELOG tables bound summed over the three level tables (`assert_table_bound` with a running total), number cells 25; position anchor charged (equine records 1,966,163); `report_guard.rs` header; RUST.md counts (draft 4,600 lines, tests 11/2/18/5/3/7), ASCII letter wording, rows rewritten.
|
||||
|
||||
## Round 11
|
||||
|
||||
Fresh verifier and security on the fixed commit: below.
|
||||
Reference in new issue
Block a user