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

14 KiB
Raw Permalink Blame History

SECURITY — VERDICT: PASS TOOL: semgrep 1.168.0 — p/security-audit, p/secrets, p/owasp-top-ten SCOPE: 37 files BLOCKING: (none) REPORTED (non-blocking):

  • [MEDIUM] report-guard/wiki-link-across-code-spans (silent family F2) — crates/core/src/curation/report_guard.rs:55-59 (rule applied per plain part from :177-183); crates/core/src/curation/draft/review_report.rs:90-100
  • [MEDIUM] report-guard/opener-closed-inside-code-span (silent family F1) — crates/core/src/curation/report_guard.rs:178-179; crates/core/src/curation/draft/fields.rs:104-112,123-125; crates/core/src/curation/draft/review_report.rs:91-98
  • [LOW] declaration/code-spans-called-generator-only — docs/development/RUST.md:3166-3173,3176-3178,3221-3230; crates/core/src/curation/report_guard.rs:14-17
  • [LOW] report-guard/quadratic-cost-per-line — crates/core/src/curation/report_guard.rs:116-122,126-141,55-59
  • [LOW] anti-gaming/test-only-clippy-allow (context, not a security suppression) — crates/core/tests/curation_review.rs:6; crates/core/tests/curation_markdown.rs:6 PROOF: semgrep 162 rules on 37 files → 0 findings; checklist 9 checks → 1 finding (LOW); guard differential (Rust format_report vs Prettier 3.8.3 with the repository options) 147,789 report documents, then the Rust pipeline vs the TypeScript pipeline end to end on 13 changesets → 2 silent families reproduced end to end (MEDIUM), 2 LOW

Security gate 5, R5.4 review files (2026-10-23)

Scope: git diff c6e0d85..1b12d90 (HEAD of feature/rust-r5-pipeline-core), 37 files, read from a pristine git archive copy of 1b12d90 in the session scratchpad. Product files read whole: curation/report_guard.rs, curation/markdown.rs, curation/mod.rs, draft/changelog.rs, draft/review_report.rs, draft/svg_compare.rs, draft/drawing.rs, draft/overlay.rs, draft/app_review.rs, draft/fields.rs, bin/import_equine.rs, the diffs of pipeline.rs, ops.rs, mod.rs and Cargo.toml, RUST.md §11.14 and §11.15, and the TypeScript sweep generator.

Grading

No HIGH or CRITICAL: the inputs are the owner's own changes.json and references.json, the tool is never deployed and exposes nothing, and no finding crosses a security boundary (no write outside the claimed folder, no seed modification, no code execution). The two MEDIUMs breach the owner's stated contract for this tool ("a report never differs silently from what the TypeScript+Prettier pipeline wrote: byte-identical or loudly refused"). The gate does not block on them, but by that contract they are defects to fix before R5.4 closes. Both were reproduced end to end: the raw texts of the two pipelines are identical, the Rust CHANGELOG.md is identical, and the Rust REVIEW-REPORT.md differs from the TypeScript one with no refusal.

Both new families have one root cause. The guard decides inline constructs per stretch of text between two backticks. Prettier's parser builds wiki links, link references and liquid tags across the generator's code spans, and its bracket counting does not see code spans at all.

rewritten_construct (report_guard.rs:53-80) runs on each plain part separately (guard_text, :177-183). Its padded wiki rule (:55-59) needs the [[ and the ]] in the same plain part. In the review report, change_line (review_report.rs:90-100) writes the title and the rationale before the generated Objets : \…`andRéférences : …code spans and the question after them, all on one line. A[[in the title or rationale and a]]` in the question form one wiki link that spans the code spans. Prettier's wiki-link plugin trims its content, so a space next to either bracket is dropped. The guard never sees the pair.

Reproduced end to end on the sweep's mini sheet (Rust apply_changeset, render_review_report, format_report against the TypeScript applyChangeset, renderReviewReport, formatMarkdown). Changeset: one level C change, op set finding:hip/hip-dysfunctions/mobility name.en = "Mobility", title Mobilité, rationale Libellé repris de [[, question Faut-il garder ]] ?:

rust: … Libellé repris de [[ Objets : `finding:…name.en`, … Question : Faut-il garder ]] ?
ts  : … Libellé repris de [[Objets : `finding:…name.en`, … Question : Faut-il garder]] ?

The same happens with title Renommer [[mobilité and question Garder le nom ]] ?, with rationale Voir [[ la fiche and question Confirmer]] ?, and with title Mobilité [[ (the generator's following space pads it). Three random seeds of a mixed sweep without any field trick (48,000 documents, 26,244 admitted) gave 55 silent differences, all from this family.

How contrived: the changeset is fully valid and the document is untouched. It only needs wiki-link brackets split between the title or rationale and the question of one change, with a space next to one bracket. Wiki-link syntax is rare in French clinical prose, so accidental occurrence is unlikely, but no malformed data is involved.

Fix direction: evaluate the construct rules on the whole line, code spans included, the way the parser does (at least: a [[ with a later ]] anywhere on the line, a space next to either); or refuse [[ and ]] in the list-item fields unless they form a closed, unpadded pair inside the same field. Add cross-field probes to the sweep. Today it puts the same probe in every field, so an opener in one field and its closer in another lies outside it by construction.

MEDIUM 2: an authored opener closed inside a generated code span (F1)

Inside a code part, the guard admits anything but a carriage return or a tab (:178-179). The module doc and RUST.md call code spans "the generator's alone (ids, targets, field names)", but field names are authored. is_settable checks only the first segment of a set field (fields.rs:123-125), and split_field refuses only empty segments, control characters, backticks, NUL starts and __proto__ (:91-121). Any other sub-segment reaches the review report's Objets code spans through record_subject. If the title or the rationale holds an unclosed [, [[ or {%, the parser closes it at a ], ]] or %} inside that code span, re-pairs every backtick after it, and re-prints the rest of the span as Markdown.

Reproduced end to end. Change title Mobilité [voir note. Ops: set finding:hip/hip-dysfunctions/mobility name.<130 × "p">.a]_ = "x", then set … name = {"fr":"Mobilité","en":"Mobility"}. The second op makes the final document valid again, and the padding pushes the stray key past the CHANGELOG's 120-unit value cut, where the guard would otherwise refuse it:

rust: … Objets : `finding:…name.ppp….a]_`, `finding:…name`, …
ts  : … Objets : `finding:…name.ppp….a]\_`, `finding:…name`, …

Other reproduced variants: title Titre [[x with segment a]] *b* (TS prints _b_), Titre [x with a][b (TS prints a]b), Titre {%x with a%} *b*, and the opener in the rationale. The same breakage also turns the tail of a code span into live Markdown. With segment a] [lien](https://example.org) <b>gras</b> x and title voir [x, the parsed report holds a link and two inline HTML nodes, and , becomes a code span. Both pipelines print that identically, so it is no silent difference, but it gets past the guard's "no link, no HTML tag" rule. The author already controls the file, so nothing is gained in privilege.

How contrived: very. It needs a field path with a stray sub-segment (a typo-class authoring error) that a later op overwrites or removes, because every sheet object is strict and the final document would be refused otherwise. The stray key must also stay out of the first 120 UTF-16 units of every CHANGELOG value, or the guard refuses it there and the whole run stops. And the change's title or rationale needs an unclosed opener.

Fix direction: refuse at split_field any segment outside the id alphabet ([A-Za-z0-9_-], which every settable path uses: name.fr, view_box.min_x, count_range.min). That is a declared refusal where the TypeScript accepted. Then make the code-span rule an allowlist of what the generator really writes (ids, CHG-ddd, kind:id/…, dotted field names).

LOW: the residual-risk declaration is accurate in kind, wrong in two specifics

§11.14 and §11.15 correctly call the guarantee empirical and say an unprobed combination could still differ. Two statements are false as written, though. "Code spans are the generator's alone (ids, targets, field names); inside them, anything but a carriage return or a tab" (RUST.md :3170-3173, report_guard.rs:14-17) hides that field sub-segments are authored, and that this channel has the weakest rule of the guard. "Nested padded wiki links" and the other constructs are listed as ruled (:3166-3168), but they are ruled only within one stretch between backticks. The sweep's blind spot also deserves a line: one probe copied into every field never puts an opener and its closer in two different fields. Fix: correct the module doc and §11.14 and §11.15 when F1 and F2 are fixed.

LOW: quadratic guard cost per line

in_url_token (:116-122) scans back to the token start for every & that is followed by a lowercase letter (:129). The padded-wiki rule (:55-59) runs contains over the rest of the part for every [[ or ]]. Measured on the release build: a 160 kB token https://x.org/?a=1&b=1&b=1… takes 4.1 s and a 640 kB one 28.4 s. 640 kB of ]] takes 5.6 s. Memory stays flat (8 MB). Authored texts have no length cap below the 16 MiB file bound (MAX_FILE_BYTES), and each text is guarded in two or three lines, so a multi-megabyte rationale stalls the run for minutes to hours. It is owner-authored and can be interrupted. Fix: one forward pass (track the current token's start and whether it holds a URL literal; precompute the first [[ and the last ]] of the line), or a length cap on authored texts.

LOW: new lint allows (anti-gaming, context)

#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)] heads the two new integration test files (curation_review.rs:6, curation_markdown.rs:6), the same as the pre-existing curation_draft.rs:7. These are test-only lint allows (oracle file reads, unwraps) in separate test crates. They do not weaken the library's no-I/O rule and do not silence a security scanner. The diff adds no nosemgrep, nosec, eslint-disable, ts-ignore or noqa. Not blocking.

Checked and clean

  • semgrep, pinned packs, --metrics=off (EIO_BACKEND=posix), 37 files (rs, ts, md, json, toml): 0 results, 0 errors.
  • Checklist: no secret, token, key or credential URL in the added lines (pattern grep plus p/secrets). No SQL built in the diff (the seed SQL renderer is unchanged R5.3 code). No innerHTML, eval or HTML sink. No endpoint, so no authz surface. No secret in a log. No tracked .env or credential file (the tracked .env.example is the placeholder convention, outside the scope; reading it was refused by a permission deny rule, so it was not opened).
  • Guardrails scanner (--domain api,supabase, on the pristine copy): 0 FAIL, 1 WARN, 1 MANUAL. The WARN (SB-POLICY-NOT-OWNER, supabase/migrations/20261008110000_anatomical_sheets.sql:1177) is in a file outside the diff and is excluded.
  • No authored text reaches a report outside the guard: both reports go through format_report (pipeline.rs). Every authored field the reports print passes assert_authored (changelog.rs:70-71, 91-92; review_report.rs:361-389). Cell pipes are escaped and an authored \| is refused. Line breaks become spaces in cells and are refused in list items. A row with another cell count is refused. No authored text ever starts a line, so no heading, section, list or table can be forged. Code spans are the exception, see F1.
  • Drawings: every label, id, path and number goes through the core serializer's escaping, and first_unwritable refuses XML-invalid text and CR. View ids used in file names are stable ids, and write_exclusive accepts only plain components.
  • Strict SVG comparison (svg_compare.rs): the committed file must rebuild byte for byte from its tree, the rule must change that tree, and the rebuilt text after the rule must equal the produced file byte for byte. The rule touches only data-anno-name-en and FR / FR titles of elements that open a view, so it cannot hide another difference.
  • import-equine --check, built in the scratch copy (read-only): legacy-import: 6 files, 0 differences, draft: declared: review/app-main.svg …, draft: 12 files, 0 differences, exit 0. Its --out path checks (no .., parent canonicalized, seed refused by path and by inode, symbolic link refused, non-empty refused, create_dir and create_new only) were read, not run.
  • Panics: none found by reading the guard's slicing. A fuzz of 20,000 random multi-line documents (tabs, CR, combining marks, U+2028, emoji, ZWJ, backticks, brackets) produced no panic.

Method

Throwaway probes in the scratchpad only: examples/guard_probe.rs (calls format_report) and examples/pipeline_probe.rs (the sweep's pipeline on a changes file), linked against the pristine copy with --features curation; Node scripts running the repository's Prettier 3.8.3 with the options of packages/anatomy/src/format.ts, and the TypeScript pipeline of packages/anatomy/src through the tsx loader. Differential harness: raw report lines built like the reports (list items, ordered items, table rows with cell() escaping), admitted by Rust then compared with Prettier. Code-span channel: 1,476 documents, 0 silent without an opener. Random authored text: 66,000 documents, 48,737 admitted, 0 silent. Openers against code-span contents: 8,312 documents (F1). Mixed fields: 72,000 documents (F1 and F2 only, every silent case classified). Fuzz: 20,000. End to end: 13 changesets. No --out was run, nothing was deleted, and no file of the repository was modified except this report.