Files
faunosteo/.claude/audits/2026-10-23-rust-r5-review-security-10.md
T

9.6 KiB
Raw Blame History

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-.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.