171 lines
11 KiB
Markdown
171 lines
11 KiB
Markdown
```
|
|
SECURITY — VERDICT: PASS
|
|
TOOL: semgrep 1.168.0 — p/security-audit, p/secrets, p/owasp-top-ten
|
|
SCOPE: 35 files
|
|
BLOCKING:
|
|
(none)
|
|
REPORTED (non-blocking):
|
|
- [MEDIUM] author-data-silently-replaced (non-array `children` of an added item) — crates/core/src/curation/draft/ops.rs:252 + crates/core/src/curation/draft/targets.rs:246
|
|
- [LOW] check-lists-through-top-level-folder-link — crates/core/src/bin/import_equine.rs:193 (listed, :164)
|
|
- [LOW] seed-containment-is-path-based (bind-mount alias) — crates/core/src/bin/import_equine.rs:230 (inside, :253)
|
|
- [LOW] declared-depth-walk-cost-understates-cap-bound-worst-case — crates/core/src/curation/draft/apply.rs:110 / docs/development/RUST.md:3046
|
|
- [LOW] unit-test-fixture-in-shared-temp-with-fixed-name — crates/core/src/bin/import_equine.rs:383
|
|
- [LOW] context: clippy purity lint allowed in a new test file (project convention, not a scanner suppression) — crates/core/tests/curation_draft.rs:7
|
|
- [LOW] context: seed SQL rendered by string formatting from pipeline values — crates/core/src/curation/draft/seed.rs:29
|
|
PROOF: semgrep 129 rules on 35 files → 0 findings; checklist 9 checks → 7 findings (1 MEDIUM, 6 LOW)
|
|
```
|
|
|
|
# R5.3 draft, security gate (fresh, final 4)
|
|
|
|
Branch `feature/rust-r5-pipeline-core`, HEAD `6c0fe88`, scope `git diff 5e114da..HEAD`
|
|
(35 files, 11 commits), with attention to `86273b6`. Read whole: `bin/import_equine.rs`,
|
|
`curation/draft/{shape,ops,apply,schema,targets,fields,records,rename,stats,migration_map,seed,pipeline,mod}.rs`,
|
|
`curation/mod.rs`, `scripts/import-equine.sh`, the `package.json` line, the binary and
|
|
integration tests that touch the file system, the oracle generator's write guard
|
|
(`MAKE_R5_ORACLES=1` only). Every probe ran in
|
|
`/tmp/claude-1000/-home-bchanot-Documents-faunosteo/9b0edf59-ccd2-4662-b90c-e473dd78028e/scratchpad/sec4.j5fliv`
|
|
on a copy of the seed, through a probe binary that is `import_equine.rs` byte for byte except
|
|
the `SEED` constant (pointed at the copy). Nothing ran `--out` against the repository, nothing
|
|
was deleted, `git status` is clean after the run.
|
|
|
|
## Semgrep
|
|
|
|
`semgrep scan --config p/security-audit --config p/secrets --config p/owasp-top-ten
|
|
--metrics=off` on the 35 existing files of the diff: 129 rules run, 0 findings, 0 errors.
|
|
The rulesets carry almost no Rust rules; the Rust code was covered by reading and probing.
|
|
|
|
## Checklist
|
|
|
|
| Check | Result |
|
|
|---|---|
|
|
| Hardcoded secret / token / key / auth URL | none (grep over the 35 files) |
|
|
| SQL by string interpolation | `seed.rs` renders the seed file by formatting: LOW context below, not a runtime query |
|
|
| Unsanitized render (innerHTML, eval…) | not applicable (Rust CLI and library, no DOM) |
|
|
| Sensitive endpoint without authz | not applicable (no endpoint) |
|
|
| Stack trace / internal path to an end user | not applicable (errors go to the local developer's stderr) |
|
|
| Secret / PII in a log | none (stdout/stderr carry paths, counts and refusals) |
|
|
| Tracked `.env` / credential file | only `.env.example` tracked |
|
|
| Guardrails scanner (`--domain api,supabase`) | 0 FAIL, 1 WARN (`SB-POLICY-NOT-OWNER`, `supabase/migrations/20261008110000_anatomical_sheets.sql:1177`, outside the diff, dropped), 1 MANUAL |
|
|
| New suppressions (anti-gaming) | no `nosemgrep`, `nosec`, `eslint-disable`, `ts-ignore`, `noqa`; one clippy allow in a new test file (LOW context below) |
|
|
|
|
## Owner requirements, verified
|
|
|
|
- Seed never modified automatically: every read goes through `read()` (canonical path inside
|
|
the canonical seed, regular file, 16 MiB cap). Probed: `curation/` as a folder link out of
|
|
the seed and `changes.json` as a file link out of it are both refused (`leads outside the
|
|
seed folder`); a folder link that stays inside the seed is accepted.
|
|
- `--check` writes nothing: only `canonicalize`, `metadata`, `read`, `read_dir` on that path.
|
|
Probe copy: 12 files, 0 differences, nothing new under the fixture seed (`find -newer`).
|
|
- `--out` refusals, probed on the fixture seed: a link to the seed and to `draft/` (as the
|
|
destination and as its parent), a link chain `p/q` ending in a seed link, the seed path
|
|
itself plus `/new`, `legacy-import/new`, `INIT_CWD` set inside the seed, `..`, an empty path,
|
|
`/`: all refused, nothing created. A relative `INIT_CWD` is ignored. A valid destination
|
|
gets 12 files identical to the seed (`diff -rq`), a second run on it is refused `not empty`.
|
|
Files are `create_new`, folders `create_dir` tracked in `created`, so an entry that appears
|
|
after the claim is refused. File names are pipeline constants.
|
|
- Strict changeset validation, depth and resource caps: `deny_unknown_fields`, the `op`
|
|
discriminator, non-empty strings, the shape comparison (now with array length), reserved
|
|
NUL keys at parse and in field paths, 8 field segments, serde_json's 128 parse depth, 64
|
|
document levels after each op (iterative walk), 16 MiB per file. Recursive walks
|
|
(`reserved_key`, `first_mismatch`, `strip_marks`, `walk`, `touch_tree`, `js_deep_equal`) are
|
|
all bounded by the 128 parse depth or the 64-level check.
|
|
- `86273b6`: `assert_object_children` refuses a non-object entry of a `children` or
|
|
`categories` list (explicit stack); the length arm of `first_mismatch` sits before the
|
|
element arm; `claim_destination(typed, seed)` with its fixture test refuses before any
|
|
`create_dir`. All correct. One gap left next to the first: MEDIUM below.
|
|
|
|
## Findings
|
|
|
|
### MEDIUM: a non-array `children` on an added item is silently replaced by `[]`
|
|
|
|
`crates/core/src/curation/draft/ops.rs:252` (`assert_object_children` skips a `children`
|
|
value that is not an array) and `crates/core/src/curation/draft/targets.rs:246`
|
|
(`children_path` overwrites any present non-array `children` with `[]`). An `add` whose value
|
|
carries `"children"` as an object, a string or `null`, followed by an `add` (or a `move`)
|
|
into that item, is accepted: the strict gate never sees the author's value, which is gone
|
|
from `document.json` and the migration map. Probed on the real equine changeset plus one
|
|
level-A change: `"children": {"author-note": {"id": "kept", ...}}` (a whole nested finding
|
|
written as an object instead of an array), `"children": "author text"` and
|
|
`"children": null` all give `probe-node.children = [probe-child]`, exit 0, 12 files written.
|
|
Only the add record's `after` keeps the value; no R5.3 output shows it (the CHANGELOG is
|
|
R5.4). Parity with the TypeScript `childrenOf`, and not declared: §11.12 says "a lean leaf
|
|
gets `children: []` appended on demand", which covers an absent key, not a present value
|
|
replaced. This breaks the owner's "author data never dropped silently" through a plausible
|
|
typo (object in place of array). Non-blocking: no security boundary is crossed.
|
|
Hint: in `assert_object_children`, refuse a present `children` or `categories` key whose
|
|
value is not an array (same message family, same place as the entry check), or make
|
|
`children_path` refuse a present non-array value and append `[]` only when the key is absent.
|
|
Declare the split in the §11.12 table with a frozen TypeScript case.
|
|
|
|
### LOW: `--check` lists through a top-level folder link
|
|
|
|
`crates/core/src/bin/import_equine.rs:193` calls `listed(&target, ...)` on
|
|
`SEED/legacy-import` or `SEED/draft` without checking the folder itself: `read_dir` follows
|
|
it when it is a link. Probed with `legacy-import` pointing out of the seed: the reads are
|
|
refused (`missing: ...`), but `not produced: private-name.txt` and `not produced:
|
|
sub/deep.txt` print the names of files outside the seed, subfolders included. Read-only,
|
|
names only, same user. §11.12's "`--check` lists a link without walking into it" holds for
|
|
entries, not for the generated folder itself.
|
|
Hint: canonicalize the target and require `inside(&canonical, &seed)` before listing, or
|
|
refuse a target whose `symlink_metadata` is a link.
|
|
|
|
### LOW: the seed guard is path-based, a mount alias passes it
|
|
|
|
`crates/core/src/bin/import_equine.rs:230` compares canonical paths (`starts_with`).
|
|
`canonicalize` resolves links, not mounts: if the seed (or the repository) is reachable
|
|
through a second path (bind mount, the same NAS share mounted twice), `--out
|
|
<alias>/.../equine/new` passes `inside` and creates a new folder inside the official seed.
|
|
Only new files (never an overwrite, never a delete); the user must type the alias. Reasoned,
|
|
not probed (a mount needs privileges).
|
|
Hint: also compare `(dev, ino)` (`std::os::unix::fs::MetadataExt`) of the canonical parent and
|
|
each of its ancestors with the seed folder's; a bind mount root shares the source's pair.
|
|
|
|
### LOW: the declared depth-walk cost understates the cap-bound worst case
|
|
|
|
`crates/core/src/curation/draft/apply.rs:110` runs `assert_depth` over the whole document
|
|
after every op; RUST.md:3046 declares it with one sample ("a 2.4 MB changeset takes about
|
|
10 s"). The sample is right (probe: 2.3 MB, one 1 M-node add then 2,000 sets, 12.4 s,
|
|
455 MB). The worst case inside the 16 MiB read cap is two orders larger: 8.2 MB, one 4 M-node
|
|
add then 1,000 sets, 35.7 s and 1.7 GB, so about 30 ms per op, and the remaining 8 MB holds
|
|
about 94,000 more ops: roughly 45 minutes of CPU before the final gate refuses. Twenty
|
|
thousand plain sets on the real document take 0.9 s, so ordinary changesets are not affected.
|
|
Local developer tool, interruptible. The declaration is not wrong, it is incomplete.
|
|
Hint: state the cap-bound figure in §11.13, or bound the work: a total node cap on the
|
|
document after each op (also bounds memory), or a depth check limited to the subtree the op
|
|
wrote.
|
|
|
|
### LOW: unit-test fixture at a fixed name in the shared temp folder
|
|
|
|
`crates/core/src/bin/import_equine.rs:383`: `env::temp_dir().join("faunosteo-import-equine-claim")`
|
|
with `create_dir_all`. On a multi-user host another account can pre-create or link that
|
|
name. The test only runs refusals, so the worst outcome is a failed test or an empty folder
|
|
created where the link points. The integration test already uses the private
|
|
`CARGO_TARGET_TMPDIR`.
|
|
Hint: put the fixture under the target folder (for example
|
|
`concat!(env!("CARGO_MANIFEST_DIR"), "/../../target/...")`) or a per-run name created
|
|
exclusively.
|
|
|
|
### LOW (context): clippy purity lint allowed in a new test file
|
|
|
|
`crates/core/tests/curation_draft.rs:7` `#![allow(clippy::disallowed_methods,
|
|
clippy::unwrap_used, clippy::expect_used)]`. A determinism and robustness lint (no I/O, no
|
|
clock in the core), not a security scanner suppression. The same line heads the ten other
|
|
core test files. The binary's `#![allow(clippy::disallowed_methods)]` was already present at
|
|
`5e114da`. Not blocking.
|
|
|
|
### LOW (context): seed SQL rendered by string formatting
|
|
|
|
`crates/core/src/curation/draft/seed.rs:29` (`sql_text`) and `:90` (`document_literal`). Every
|
|
interpolated value is a pipeline constant, a sha256 hex, a derived uuid or a byte count;
|
|
quotes are doubled (correct with `standard_conforming_strings` on, the PostgreSQL default);
|
|
the document is embedded in a `$equine_doc$` literal and refused if it holds the tag; the
|
|
formatted JSON always ends with `}`, so no tag can form at the closing boundary. This
|
|
generates a reviewed seed file, it is not a runtime query. No action.
|
|
|
|
## Residual risks declared in RUST.md §11.13
|
|
|
|
Memory without a cap beyond 16 MiB per file: confirmed (1.7 GB from an 8.2 MB file), in line
|
|
with the declaration. Single-user check-then-use window on reads and `--out`: confirmed as
|
|
described, every file stays `create_new`. Lossy UTF-8 and repeated keys: as declared. The
|
|
quadratic walk: LOW above.
|