docs(docs): R5.4 emoji refusal named at the guard, round 12 residuals declared

This commit is contained in:
bchanot committed 2026-10-23 17:13:30 +02:00
1 parent c4e717da86
commit 88e42749ec
4 files changed
+152 -6

No files matched your search

@@ -0,0 +1,129 @@
# Security gate R5.4 (round 12): review files in Rust
Date: 2026-10-23. Mode: audit (fresh, blind). Branch `feature/rust-r5-pipeline-core`, HEAD
`c4e717d`. Scope: `git diff c6e0d85..HEAD -- crates/core packages/anatomy/tests docs/development/RUST.md`
(29 files, none deleted).
```
SECURITY — VERDICT: PASS
TOOL: semgrep 1.168.0 — p/security-audit, p/secrets, p/owasp-top-ten
SCOPE: 29 files
BLOCKING:
(none)
REPORTED (non-blocking):
- [LOW] quadratic-scan (latent, unreachable today) — crates/core/src/curation/report_guard.rs:216
- [LOW] quadratic-scan (bounded, ~2 s at the document bound) — crates/core/src/curation/draft/pipeline.rs:256
- [LOW] new lint allowance (context, documented convention) — crates/core/tests/curation_markdown.rs:6, crates/core/tests/curation_review.rs:6
- [LOW] declaration precision (R5.3 code, outside the diff) — crates/core/src/curation/draft/schema.rs:430
PROOF: semgrep 128 rules on 29 files → 0 findings; checklist 9 checks → 0 findings (guardrails 0 FAIL, 1 WARN outside the diff); differential probes 38,378 admitted template reports + 898 admitted real-pipeline reports → 0 silent differences; display width 1,112,032 code points → 0 differences
```
## Tool run
- `semgrep scan --config p/security-audit --config p/secrets --config p/owasp-top-ten --metrics=off`
on the 29 scope files: 128 rules applicable, 0 results, 0 errors.
- Guardrails scanner (`--domain api,supabase`, project root): 0 FAIL, 1 WARN
(`SB-POLICY-NOT-OWNER`, `supabase/migrations/20261008110000_anatomical_sheets.sql:1177`, not in
the diff, dropped), 1 MANUAL (not reported).
## Checklist (9 checks)
| Check | Result |
|---|---|
| hardcoded secret, token, key, auth URL in added lines | none |
| SQL by concatenation | none in the diff (`seed.rs` untouched) |
| unsanitized render, `eval`, shell | none; SVG output escaped (below) |
| sensitive endpoint without authz | N/A (offline CLI, no endpoint) |
| stack trace or DB error to an end user | N/A (operator CLI; refusals print `{:?}`, control characters escaped) |
| secret or PII in a log | none |
| tracked `.env` or credential file | none (`git ls-files`) |
| guardrails scanner | run, nothing in the diff |
| new suppression (anti-gaming) | no `nosemgrep`, `nosec`, `eslint-disable`; two lint allowances in test files (LOW 3) |
## What was verified, by probe or by reading
Markdown guard (`report_guard.rs`) against Prettier 3.8.3 with the repository options, from a
scratch harness (Prettier imported from the repository's `node_modules`, the Rust guard through a
scratch crate depending on `faunosteo-core` with `curation`):
- template reports reproducing the ten list-item and cell positions of the two reports (title,
rationale, question, citation, URL, DOI, vet-flag before/after, label cell): 1,197 hand probes
(reference shapes `[a] [b]`, `[a] (b)`, `\|` outside tables, `+`/`>`/`1.`/`#` mid-line, URL
trailing punctuation and `&name=`, `_` near URLs, `**word**`), 27,000 random single-field, 10,000
random cross-field and 36,000 URL-centric cases: 38,378 admitted, 0 differ from Prettier;
- the real generators: 7,200 random changesets run through the TypeScript (`applyChangeset`,
`renderChangelog`, `renderReviewReport`, `formatMarkdown`) and through the Rust
(`apply_changeset`, `render_changelog`, `render_review_report`, `format_report`): 898 admitted,
6,302 refused, 0 raw-text differences, 0 silent formatted differences;
- `text::display_width` against Prettier's `util.getStringWidth` for `"a" + c`, every scalar value
from U+0020 to U+10FFFF: 0 differences wherever the port measures (it refuses the rest).
Report structure: authored texts carry no backtick (`assert_authored` on every authored field
of both reports), list-item fields refuse control characters, cells turn `\n` into a space and
escape `|`; ids written by `add`/`rename` are stable ids or region codes, field segments
`[A-Za-z0-9_-]`, targets resolve only to existing stable ids, so no author byte starts a line or
writes a code span. Email autolinks need `@`, which the allowlist refuses.
SVG drawings: the serializer escapes `& < >` in text and `& < > " \t \n \r` in attributes
(`]]>` cannot appear); `drawing::first_unwritable` refuses non-XML characters and CR; element and
attribute names are constants; colours are `#rrggbb` by schema; view ids (file names) are stable
ids. Drawings projection: names copied at most four times per annotation, worst escape `&` → 5
bytes per JSON byte, so `24 × (json + longest name)` holds.
Records bound: every record site goes through `Recorder::record` or `mark_to_confirm`, both
charged before the clone. Aligned tables: CHANGELOG projected from cell bytes (bytes ≥ display
width, numbers ≤ 25), every table rechecked in `align` before padding.
CLI `import_equine.rs`: reads only canonical regular files inside the canonical seed, 16 MiB
cap; `--check` refuses a generated folder that is not the seed's own, lists without following
links, compares bytes (app drawings only through the strict rebuild rule); `--out` refuses `..`,
symlinks, non-empty folders and any path inside the seed by prefix or by (dev, inode), writes
with `create_dir`/`create_new`, deletes nothing; file names from views are stable ids and
`write_exclusive` accepts only normal components. The check/use race is declared (§11.13).
Timing of the guard on adversarial lines (linear): 400,000 `& ` in 7.9 ms, 400 KB of `[[x`,
`x ]]`, `**ab**`, `<`, URL `&a=1` runs under 10 ms, a 1.4 MB 100,000-column table in 95 ms.
## Findings (non-blocking)
### LOW 1: `underscore_pairs_later` is quadratic, latent
`crates/core/src/curation/report_guard.rs:216`. For every plain part holding `_`, the function
rescans all later code parts and re-collects each into a `Vec<char>`. A synthetic line of 100,000
`` `ab` x_y `` (900 KB) took 53.7 s. Not reachable today: authored text holds no backtick, so the
generator alone interleaves code spans and plain parts, and on every line of both reports at most
two plain parts can carry an authored `_` (title with rationale, question), which keeps the scan
linear. A future line that puts authored text between generated spans would turn it quadratic.
Hint: scan the parts right to left once, keeping a "a later code part closes" flag.
### LOW 2: drawings projection walks views × annotations before the bound
`crates/core/src/curation/draft/pipeline.rs:256`. `review_drawings_bytes` runs `layer_bytes` over
every annotation for every view, and the view count is not yet bounded there (only by the
200,000-value document bound). Measured on a synthetic `DraftResult`: 10,000 × 10,000 in 1.8 s,
20,000 × 20,000 in 7.6 s; the document bound allows about 11,000 of each, so about 2 s. Hint:
group annotations by `view_id` once, or stop as soon as the running total passes the bound.
### LOW 3: lint allowances in the two new test files (context)
`crates/core/tests/curation_markdown.rs:6`, `crates/core/tests/curation_review.rs:6`:
`#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]`. The lint is the
core's no-clock, no-file-system rule; `clippy.toml` documents that tests allow it locally, and
every existing integration test file carries the same line. Not a security-rule suppression.
### LOW 4: §11.15 names `changes.json` alone for the parse amplification
`crates/core/src/curation/draft/schema.rs:430`. `parse_references` goes through the same
`json_parse` as `parse_changeset`, so `references.json` under its 16 MiB cap should hold the same
order of memory (factor not measured here). R5.3 code, outside this diff; the residual line could
name both files.
## Notes
- The working tree changed during the run (comment and doc lines only, by another agent):
`.claude/audits/2026-10-23-rust-r5-review-verify.md`, `docs/development/RUST.md`,
`packages/anatomy/tests/r5.review-synthetic-oracles.test.ts`. HEAD stayed `c4e717d`; this gate
judges the committed range.
- Declared residuals (§11.15, including the ~65× `changes.json` parse) not re-reported.
- Probes and harnesses live in the session scratchpad only; no tracked file touched, the
`import-equine` binary never run; the scratch crates read only the committed sweep oracle.
@@ -82,6 +82,14 @@ Fresh verifier and security on the fixed commit: below.
- Security (`.claude/audits/2026-10-23-rust-r5-review-security-11.md`): PASS. 146,000 random cases vs Prettier, 44,330 admitted, 0 differ; drawings wrote 0.12 to 0.41 of the projection on hostile documents. LOW test allows (convention); LOW bare URLs autolinked in any authored field (visible text = target, TypeScript alike: owner choice).
- Fixed: 4,096 bytes per drawing for its fixed parts (`pipeline::DRAWING_FIXED_BYTES`; equine projection 1,406,812 for 564,239 written), test `the_drawings_projection_bounds_what_is_written` (equine and no annotations); RUST.md counts (4,606 lines, review 12 tests); test comment sections.
## Round 12
## Round 12 on c4e717d: verifier C1 to C8 MET, C9 NOT-MET (1 doc gap) + 12 FLOOR (audit prose, reported apart); `pnpm check:all` green 16:41:34
- Verifier: own differential 37,264 cases (32,000 random biased to the admitted alphabet, 5,264 handcrafted placements), 0 silent, 0 raw difference; drawings projection ≥ written on 8 adversarial drafts (tightest margin 15,477 B, no annotations); every figure of §11.14/§11.15 checked exact. C9: the emoji refusal is named at the aligner (`UnsupportedWidth`) in RUST.md (synthetic case line, pictograph row) and the TS generator comment, while the report guard refuses first (`UnsupportedMarkdown`); `UnsupportedWidth` applies in the draft reports only to alphanumeric candidates (Ⓜ, 🅰) and in IMPORT-REPORT.
- Fixed: the two RUST.md passages and the generator comment (oracle unchanged, generator green in check mode).
- Security (`.claude/audits/2026-10-23-rust-r5-review-security-12.md`): PASS. 7,200 random changesets through both real pipelines (898 admitted, 0 raw and 0 formatted differences), 73,000 template cases (38,378 admitted, 0 differ), display width on every code point U+0020 to U+10FFFF, guard linear on stress lines. LOW `underscore_pairs_later` quadratic, unreachable (≤2 authored plain parts per line); LOW `review_drawings_bytes` views × annotations (≈2 s at the value bound); LOW test allows (convention); LOW §11.15 parse residual names `changes.json` only (`references.json` same parser).
- Declared: the four LOWs in §11.15 (no code change: a fix would restart the gates; owner decision).
## Round 13
Fresh verifier on the documentation commit: below.
Fresh verifier and security on the fixed commit: below.