diff --git a/.claude/audits/2026-10-25-rust-r5-7-security.md b/.claude/audits/2026-10-25-rust-r5-7-security.md new file mode 100644 index 00000000..cae27850 --- /dev/null +++ b/.claude/audits/2026-10-25-rust-r5-7-security.md @@ -0,0 +1,149 @@ +# Security gate: Rust R5.7 (deletion of packages/anatomy and packages/domain) + +Date 2026-10-25. Branch `feature/rust-r5-pipeline-core`. Scope `756b7ef..4e0a6c0` +(149 paths in the diff: 110 deletions, 2 renames, 37 modified or added files). +Fresh auditor, no prior verdict consulted. + +``` +SECURITY — VERDICT: PASS +TOOL: semgrep 1.168.0 — p/security-audit, p/secrets, p/owasp-top-ten +SCOPE: 39 files (the existing files of the diff; 110 deleted paths inspected through git) +BLOCKING: + (none) +REPORTED (non-blocking): + - [LOW] new-suppression (clippy allow, not a security-tool suppression) — crates/core/tests/curation_leaves.rs:6 + - [LOW] census-weakness (ledger target resolved by `fn (` presence, not `#[test]`) — apps/app/tests/unit/r5.census.test.ts:103 +PROOF: semgrep 158 rules (725 loaded, 3 packs) on 39 files → 0 findings; checklist 8 checks → 0 findings; guardrails scan.py api,supabase → 0 FAIL, 1 WARN outside the diff (filtered), 1 MANUAL (not reported); anti-gaming 1 new allow (LOW) +``` + +## Semgrep + +`semgrep scan --config p/security-audit --config p/secrets --config p/owasp-top-ten +--metrics=off --quiet --json <39 paths>`: 0 results, 0 errors, 0 skipped. The verbose +rerun confirms 725 rules loaded from the 3 packs, 158 applicable to the languages present +(TypeScript, Rust, Dockerfile, JSON, YAML, Markdown, shell), 39 files scanned. + +## Checklist (8 checks, 0 findings) + +| Check | Result | +|---|---| +| Hardcoded secret, token, key, auth URL in added lines | None. The only hit is the variable name `SUPABASE_SERVICE_ROLE_KEY` in a CLAUDE.md command description, no value. | +| SQL by concatenation | No new SQL. `crates/core/src/curation/draft/seed.rs` (doc comment only in this diff) keeps `sql_text` quote doubling and `$equine_doc$` dollar quoting; the deleted `importer.guards.test.ts` case "refuses a document that contains the dollar-quote tag" is ported as `a_document_holding_the_dollar_quote_tag_is_refused_by_the_seed` (curation_draft.rs). | +| Unsanitized render (innerHTML, eval, raw) | None in the diff. | +| Sensitive endpoint without authz | No endpoint, policy or RPC in the diff. | +| Stack trace / internal path to the user | None. | +| Secret or PII to a log | None. | +| Tracked `.env` or credential file | Only `.env.example` is tracked; `.dockerignore` excludes `.env`, `.env.*`, the gateway htpasswd and Mailpit password. | +| Guardrails scanner (`~/.claude/skills/guardrails/scripts/scan.py`, domains api,supabase) | 0 FAIL. 1 WARN `SB-POLICY-NOT-OWNER` on `supabase/migrations/20261008110000_anatomical_sheets.sql:1177` (`species_select_active`): pre-existing, file not in the diff, filtered per gate rule. 1 MANUAL `SB-RLS-LIVE`, not reported here. | + +Local paths (`/home/`, `/Users/`), user names, e-mail addresses and private IP ranges: +none in the added lines. The URL `https://www.instagram.com/paws.iin.harmony` present in the +moved fixtures is the product's existing partner credit (`apps/app/src/pdf/branding.ts`, +`components/brand/Footer.tsx`), product data, not personal data introduced by this change. + +## Anti-gaming + +One new suppression-like marker in the added lines: +`#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]` at +`crates/core/tests/curation_leaves.rs:6`. It is a clippy allow, not a semgrep, bandit or +ESLint-security suppression, and it is the identical header the 40 sibling integration tests +under `crates/core/tests/` already carry (`disallowed_methods` forbids I/O and clock in the +core library; integration tests read fixtures from disk). Reported LOW, not blocking. No +removed suppression, no `nosemgrep`, `nosec`, `eslint-disable`, `@ts-ignore`, `.skip` or +`#[ignore]` added. + +## Focus (1): controls still needed by active paths + +Pre-state references to the deleted code in production paths (`apps/app/src`, +`packages/core-wasm/src`, `packages/supabase/src`, `Dockerfile`, `docker/`, vite and tsconfig +files, `scripts/`, `.gitea/`): exactly two, both removed by the diff. + +- `Dockerfile:39-40`: `COPY packages/domain/package.json` and `COPY packages/anatomy/package.json`. +- `packages/supabase/package.json:21`: script `assets:upload:legacy` → `node scripts/upload-sheet-assets.ts`. + +Post-state: zero references in those paths (the `scripts/r4-ledger.mjs` hits are `.tsx` +file names). `pnpm-workspace.yaml` globs `packages/*`; the lockfile importers are now exactly +`.`, `apps/app`, `packages/core-wasm`, `packages/supabase`, and the Dockerfile builder stage +copies exactly those four manifests before `pnpm install --frozen-lockfile`, then `COPY . .`. +The image build is coherent with the lockfile. + +Each control the brief names lives in the Rust core and is untouched (the four `crates/core/src` +changes are doc comments only): + +| Control | Where it runs now | Present at 4e0a6c0 | +|---|---|---| +| PDF import (byte scan, capped inflation, layered read) | `crates/core/src/pdf/{read,import.rs}` | yes | +| SVG sanitising (caps, allowlist, reference graph) | `crates/core/src/anatomy/svg/{prescan,sanitize}.rs` | yes | +| Sheet integrity rules | `crates/core/src/domain/sheet` | yes | +| Seed SQL generation (quoting, dollar-tag refusal) | `crates/core/src/curation/draft/seed.rs` | yes | +| Upload tool (local-only URL, private-bucket handshake, no overwrite, key never printed) | `crates/core/src/curation/upload.rs`, `crates/core/src/bin/upload_sheet_assets`, `scripts/upload-sheet-assets.sh` (`env -u SUPABASE_SERVICE_ROLE_KEY cargo build`, then exec) | yes | +| Archive readers | `crates/core/src/domain/archive` | yes | +| N-1 Zod reader (frozen copy of the deleted domain) | `packages/core-wasm/tests/n-1/domain` | yes | + +Declared functional loss, not a security loss: the xmldom-based re-cleaning of a legacy SVG +(`packages/anatomy/src/curation/assets.ts`) is not ported; the pipeline reads the committed +cleaned `draft/assets/horse.svg` bytes and verifies them through the core reader +(`FILES.tsv` row, BDR-068). Every drawing the application loads still goes through +`anatomy::svg::read_svg` at sheet load regardless of its origin. + +## Focus (2): lockfile and supply chain + +`pnpm-lock.yaml`: 1 insertion, 69 deletions. + +- Removed: importers `packages/anatomy` and `packages/domain`; package and snapshot entries of + `@xmldom/xmldom@0.9.12`; the `deprecated:` metadata line of `eslint@9.39.4` (registry + metadata refreshed at install, same version). +- Added: `optional: true` on the `tsx@4.23.15` snapshot. `tsx` is declared in no manifest + (`git grep tsx -- '*/package.json'` → none) and stays resolved only as the optional peer of + vite/vitest. +- No new package, no version change on any package. + +## Focus (3): secrets, local paths, personal data + +See the checklist rows above: none in the 20,666-line diff's added lines. The `.claude/tasks` +contract and plan files added by the diff were in the semgrep scope and the grep; clean. + +## Focus (4): the new tests + +New or extended Rust tests (`curation_leaves.rs` new, 263 lines; additions in `curation_draft`, +`curation_format`, `curation_review`, `anatomy_compose`, `report_contract`, `archive_rules`, +`archive_support`, `report_rules`): fixture access is read-only through `common::repo_path` / +`repo_file` (`CARGO_MANIFEST_DIR/../../`) and the frozen oracles; `files_under` walks +the two seed folders with `read_dir` only. No network, no `std::process`, no `std::env` +read, no write, no delete in the added code. + +The one test in these files that spawns a process and writes (`import_equine`, `out_fixtures`, +`out_refuses_every_unsafe_destination_and_writes_nothing`, `curation_draft.rs` ~768-816) is +pre-existing (before the diff's second hunk at line 963): it writes fixed fixtures under +`CARGO_TARGET_TMPDIR/import-equine-out` only and asserts the binary refuses every unsafe +`--out` destination (symlink, file, non-empty folder, `..`, absent parent) with exit code 2 +and writes nothing. Not changed by this diff. + +`archive_rules.rs` and `archive_support/mod.rs` only repoint the two moved fixtures +(`crates/core/tests/fixtures/report-v2.{full,minimal}.json`, R100 renames) and a doc comment. + +## Focus (5): census tests not vacuous + +`apps/app/tests/unit/r5.census.test.ts` (new) asserts positive facts before the negatives: +the manifest list must contain the four remaining packages; the lockfile importer set must +equal the manifest set exactly; `packages.length > 100` and a `zod@` key must be found; the +scanned source set must exceed 100 files and must contain the `@faunosteo/core-wasm` +specifier; the Dockerfile `COPY ` list must contain the two package manifests and +each copied manifest must exist; `FILES.tsv` must hold more than 80 rows with each counterpart +present; `LEDGER.tsv` must hold exactly 407 rows (144 anatomy, 263 domain), each oracle path +present and each `cargo ::` target resolved to a `fn (` in the right file; +the two moved fixtures are pinned by SHA-256; ten oracle and N-1 paths must exist. +`r4.census.test.ts` gains `@faunosteo/anatomy` and `@xmldom/xmldom` in the bans and replaces +the "xmldom only under packages/anatomy" assertion by an importer-list assertion with its own +non-vacuity check (`arrayContaining(['.', 'apps/app', 'packages/core-wasm'])`). + +Weakness reported LOW: `cargoTargetFile('faunosteo_core')` accepts a `fn (` anywhere +under `crates/core/src`, so a ledger row pointing at a non-test function would pass. The ban +regexes and the specifier scanner cover `from`, `import()` and `require()` forms and relative +`anatomy/src` / `domain/src` paths. + +## Not done (out of scope or forbidden) + +No command executed from the repository other than semgrep, the guardrails scanner and +read-only git / grep. No test suite run, no `cargo` invocation, no Supabase access. The +runtime behaviour of the ported tests is attested by the dev's own gate, not by this audit.