Files
faunosteo/.claude/audits/2026-10-23-rust-r5-draft-security-final6.md

12 KiB
Raw Permalink Blame History

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

  • [LOW] seed-guard-destination-identity — crates/core/src/bin/import_equine.rs:236 (destination branch :243-253)
  • [LOW] cite-membership-linear (doc precision, RUST.md §11.13) — crates/core/src/curation/draft/ops.rs:401-405
  • [LOW] sql-built-by-formatting (checked, not injectable) — crates/core/src/curation/draft/seed.rs:29-135
  • [LOW] new-lint-allow-in-test (context, not a scanner suppression) — crates/core/tests/curation_draft.rs:7 PROOF: semgrep 163 rules on 38 files → 0 findings; checklist 14 checks → 4 findings

Security gate, R5.3 curated draft, sixth final round (fresh, blind)

  • Repository: /home/bchanot/Documents/faunosteo, branch feature/rust-r5-pipeline-core, HEAD c6e0d85.
  • Scope: git diff 5e114da..HEAD, 38 files, all present. Focus on f245b3e.
  • Product files read in full: crates/core/src/bin/import_equine.rs, crates/core/src/curation/draft/{apply,fields,migration_map,mod,ops,pipeline,records,rename,schema,seed,shape,stats,targets}.rs, crates/core/src/curation/{mod,text}.rs, scripts/import-equine.sh, and the diffs of crates/core/Cargo.toml and package.json. The test files and the TypeScript oracle generator were checked for file system and process calls.

Semgrep

EIO_BACKEND=posix semgrep scan --config p/security-audit --config p/secrets --config p/owasp-top-ten --metrics=off --quiet --json <38 files>: 163 rules run (javascript 73, generic 57, typescript 11, python 6, package managers 5, json 3, java 3, scala 3, bash 1, ruby 1), 38 files scanned, 0 findings, 0 errors. The pinned packs hold no Rust rule, so the Rust code is covered by the reading, the checklist and the probes below.

Checklist (14 checks)

# Check Result
1 Hardcoded secret, token, key, auth URL (whole diff incl. docs, .claude, oracle JSON) none
2 SQL built by string formatting seed.rs generator, quoting verified: LOW 3
3 Unsanitized render, eval, unsafe, process spawn none in scope
4 Sensitive endpoint without authz not applicable (dev CLI and library, no endpoint)
5 Stack trace, internal path, DB error to an end user none (CLI messages go to the developer running the tool)
6 Secret or PII in a log none (stdout and stderr carry paths, counts, refusals)
7 Tracked .env or credential file none (.env.example only, pre-existing, outside the diff)
8 Guardrails scanner (--domain api,supabase) 0 FAIL, 1 WARN SB-POLICY-NOT-OWNER at supabase/migrations/20261008110000_anatomical_sheets.sql:1177, outside the diff, filtered out; 1 MANUAL not reported
9 New suppressions (anti-gaming) no nosemgrep, nosec, eslint-disable, ts-ignore, noqa; one clippy allow in a test file: LOW 4
10 --check writes nothing built binary run: 12 files, 0 differences, 6 R5.4 files listed as pending; seed file list and mtimes identical before and after; git status clean
11 --out destinations 11 probes in a fresh mktemp -d under the scratchpad, all as designed (below)
12 Seed guard of --out (canonical path, then device/inode over the seed tree) holds for every parent path; the destination folder itself is not identity-checked: LOW 1
13 __proto__ field segments refused at every position, before any write (probe below)
14 Resource caps and id comparisons parser depth, 8 segments, 64 levels, 200,000 values hold; hash sets in distinct, assert_declared, duplicates keep the old semantics; one linear membership left in cite: LOW 2

Probes (scratchpad only; no --out into the repository; no recursive delete)

The binary was built with CARGO_TARGET_DIR in the scratchpad (cargo build --release --locked --offline -p faunosteo-core --features curation --bin import-equine). Two throwaway probes ran there: one linking faunosteo-core with curation, and one compiling lines 213-293 of import_equine.rs verbatim against a scratch seed tree.

  • split_field: __proto__, name.__proto__, name.__proto__.x and name.fr.__proto__ are all refused with reserved key "__proto__". name.__proto__ (trailing space), name.__PROTO__, name.constructor and name.prototype are plain keys, as in JavaScript on a plain object. A NUL segment, 9 segments and an empty segment are refused. apply_changeset with set name.__proto__… followed by an overwriting set name refuses at CHG-001 op 0 in all four variants. is_settable calls split_field before item_at_mut, so nothing is touched or written first.
  • Identity guard (verbatim copy, scratch tree seed/{a/b/c,d} plus a link to / and a link loop inside it): the walk records 5 identities and follows neither link. seed/a/b/new, seed/new, a parent link into seed/a/b and a parent link to seed are all refused as inside the seed folder, with nothing created. A final link, a trailing / and a trailing /. are refused as a symbolic link. A sibling folder is accepted. With one seed folder made unreadable (chmod 000, restored afterwards), every claim is refused: the walk fails closed.
  • Real binary --out: absent folder (12 files written, then diff -r against the seed shows only the 6 R5.4 files); the same folder again (not empty, exit 2); an empty folder (written); a regular file (not a folder); a final link, with / and /. (a symbolic link, exit 2, link target left empty); empty/../x (.. refused); a missing parent; "" (usage error); a relative path with INIT_CWD unset (typed from the current folder, the canonical path printed before the first write). No entry appeared outside the probe folder.
  • Cite cost (release build): citing 28,000 declared ids twice on one finding takes 0.92 s, four times 2.7 s. The value bound then refuses a larger registry plus its citations.

Findings (all non-blocking)

LOW 1: the destination folder itself is never identity-checked

crates/core/src/bin/import_equine.rs:236 runs inside_by_identity(&parent, seed), which checks the ancestors of the canonical parent. When the destination already exists (:247-253), only its emptiness is checked, never its own (device, inode). Suppose an existing empty folder is a second mount path (a bind mount, or a share mounted twice on the same device) of an empty folder of the seed. The claim accepts it, and write then creates legacy-import/… and draft/… inside the seed tree. A mount alias of a non-empty seed folder is refused as not empty.

Why only LOW: this needs an empty folder under the seed (none in the checkout: find … -type d -empty returns nothing, and git tracks no empty folder) plus a mount made by hand at the destination. Every write is create_dir or create_new, so nothing is overwritten or deleted. Also, the §11.13 sentence "a second mount path of the seed or of any of its folders on the same device is refused too" holds for every parent, but not for the destination itself. Traced by reading, not reproduced: a mount needs privileges and is the user's to run.

Suggested fix: in the existing-folder branch, also refuse when inside_by_identity(&root, seed) is true (root.ancestors() starts with root itself). Alternatively, run the identity check on root once it exists, created or not. Or narrow the §11.13 sentence to the ancestors of the destination.

LOW 2: one cite comparison is still linear, while §11.13 says cite uses hash sets

crates/core/src/curation/draft/ops.rs:401-405: for each scope entry, every distinct cited id is checked with before.contains(&Value::from(id)) on the item's existing citations. That costs O(distinct × existing) per item. distinct and assert_declared are hashed now, but this membership is not, and §11.13 reads "id comparisons use hash sets (cite, declared references, duplicate ids)". Measured: about 0.9 s per repeated op at the largest registry the 200,000-value bound admits (about 28,000 references, each serialised as 6 values). Spread over a subtree, the worst case is about twice that. A 16 MiB changeset therefore stays in minutes, the same order as the declared CPU residual. So this is a precision issue in the declaration, not a new risk.

Suggested fix: build a HashSet<&str> of the string entries of before once per item and keep the output order by walking distinct. Or reword §11.13 ("cite deduplication and the declared check are hashed; the check against existing citations is linear, bounded by the value bound").

LOW 3: seed SQL built by string formatting, checked and not injectable

crates/core/src/curation/draft/seed.rs:29-135. This is a checklist hit on "SQL built by interpolation", but the code writes a generated seed file, not a runtime query. The sql_text values are pipeline values: the sheet id from the legacy import, sha256 hex, the asset id derived from it, the fixed file name and the constant change note. All of them are quoted by doubling '. The authored document goes into a $equine_doc$ dollar-quoted literal, and a document text that holds the tag is refused (:91). The text is format_json of an object, so it begins with { and ends with } after trimEnd, and no tag can form at a junction. Same construction as the TypeScript. No action needed. If this is touched later, keep the tag check on the final text.

LOW 4 (context): lint allow in a new integration test

crates/core/tests/curation_draft.rs:7 #![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]. Every other core test file carries the same allow, and clippy.toml documents it ("Tests and the worker binary allow these lints locally where they own I/O"). It silences no security scanner, so it is not a gated suppression. The binary's #![allow(clippy::disallowed_methods)] (import_equine.rs:15) was already present at 5e114da. The core library itself has no file system, environment, clock or process call (grep over crates/core/src outside bin/).

Owner requirements, checked

  • The official seed is never modified automatically. --check was run and is read-only. --out refuses every parent inside the seed by canonical path and by identity over the whole seed tree (exception: LOW 1, the destination itself).
  • --out never deletes (the binary has no remove call) and never overwrites (create_dir, create_new, the claimed folder re-checked before each file). It refuses an empty path, .., a missing parent, a symbolic link (trailing / and /. included), a non-folder and a non-empty folder.
  • Strict changeset validation: strict shapes plus the shape comparison; NUL keys refused at parse and in field segments; __proto__ segments refused at the op; non-list or non-object children refused at the add.
  • Depth and resource caps: parser 128 levels, field path 8 segments, document 64 levels and 200,000 values after each op, source files under 16 MiB. The seed walk is iterative and follows no link.
  • Author data is not dropped silently. An overwritten value is recorded as before, and the cases with no faithful reading (__proto__, NUL keys, non-list children) refuse.
  • The residual risks declared in §11.13 (record memory, the per-op bound walk, the single-user check-then-use window, lossy UTF-8 and repeated keys, a share mounted twice on distinct devices) match the code. The exceptions are the two wording points in LOW 1 and LOW 2.

Notes (no severity)

  • When the seed walk fails, the refusal reads inside the seed folder (import_equine.rs:287-289). That fails closed, but the message is misleading. Something like "seed folder unreadable" would point at the real cause.
  • The doc comment of crates/core/tests/curation_draft.rs:520-526 lists __proto__ among the ordinary keys, then says it is refused. It is stale wording in a test.

Not done

  • The pinned semgrep packs have no Rust rules: Rust coverage comes from the reading, the checklist and the probes.
  • LOW 1 was traced by reading. No mount was made.