fix(worker): V1-2.3 hostile corpus through verify, verdict and memory caps aligned

This commit is contained in:
bchanot committed 2026-11-01 17:55:49 +01:00
1 parent 7043d39ae0
commit 6aa85fe7e4
7 files changed
+67 -10

No files matched your search

+21 -1
View File
@@ -4465,7 +4465,7 @@ Contract `.claude/tasks/contracts/2026-11-01-v1-2-3-worker-verification.md`, pla
|---|---|---|
| M6 | `claim_sheet_verifications`, `get_sheet_verification_input`, `complete_sheet_verification`, `fail_sheet_verification`, service role only (claims checked too); the verdict checked for its binding (stale) and its structure (malformed), nothing written otherwise | `supabase/migrations/20261101100000_sheet_verification_jobs.sql`, pgTAP `021` (51) |
| Link | the worker links `faunosteo-core` (default features: no PDF, no curation); `version` prints the core version | `crates/worker/Cargo.toml` |
| Child | `verify`: framed stdin (`[u32 LE header length][header JSON][document][base][drawings]`), `compute_verdict`, verdict JSON out; same sandbox as `decode`, its own limits (12 MiB in, 4 MiB out, 1 GiB, 60 s CPU, 90 s); a frame the child cannot read is a broken parent (`frame_invalid`), never content | `verify_frame.rs`, `verify.rs`, `limits.rs` |
| Child | `verify`: framed stdin (`[u32 LE header length][header JSON][document][base][drawings]`), `compute_verdict`, verdict JSON out; same sandbox as `decode`, its own limits (12 MiB in, 3 MiB out under the 4 MiB SQL cap, 1 GiB, 60 s CPU, 90 s; container `mem_limit` 1 280 MiB so the child limit binds first); a frame the child cannot read is a broken parent (`frame_invalid`), never content | `verify_frame.rs`, `verify.rs`, `limits.rs` |
| Spawner | per command: `Spawner::for_decode` (unchanged values), `Spawner::for_verify`; a verify output counts only when it parses as a JSON object | `spawn.rs` |
| Mode | `run --jobs sheet-verify`: no sweep; drawings fetched under the archive caps, anything else passed without bytes for the core to name; §6.5 rows mapped to closed worker codes; watchdog stage `VERIFY` 95 s | `run.rs`, `verify_job.rs`, `backend.rs`, `http.rs` |
| Compose | service `worker-verify`, profile `worker`, same hardening as `worker` | `docker-compose.yml` |
@@ -4491,6 +4491,26 @@ Proofs (2026-11-01):
- Upgrade rehearsals on the sandbox: from the state before M6, and from the state before M4 (the DEV state, M4 to
M6 in one `migration up`): pgTAP 1 859 PASS, `verify-e2e` 7/7, `types --check` equal.
- Not measured: the largest input the policy allows (a 2 MiB document, its 2 MiB base and four drawings, 6 MiB).
- Hostile corpus: the 42 SVG files of `crates/core/tests/fixtures/svg/hostile` as the drawing of a submitted sheet,
each through the real `verify` child under the full filter (`the_hostile_svg_corpus_fails_verification_inside_the_sandbox`,
added after the verifier's review): every one a `failed` verdict with a `verification.integrity.svg_*` code, no
signal, no crash. `pnpm worker:test` then 24 sandbox tests.
Reviews (fresh, 2026-11-01, on `7043d39`):
- Security: PASS, semgrep 0 on the pinned rulesets. MEDIUM pre-existing hygiene (the throwaway sandbox account's
password literal in `scripts/db-sandbox.sh`). LOWs fixed: the verdict cap measured twice (child output now
3 MiB, under the 4 MiB SQL measure of `jsonb::text`); the child's 1 GiB address space above the container's
512 MiB (`worker-verify` and the sandbox worker now 1 280 MiB, so the child's limit binds first). LOWs open: no
backoff between attempts (the §6.4 design « without backoff »: an outage of a few seconds can spend the five
attempts, the round closing `unavailable`; fail-closed, availability only); a document naming several hundred
registered drawings overflows the 64 KiB frame header and is reported `resource_limit` instead of the core's
`caps` (wrong exit message, no security effect); SQL interpolation of generated ids in the sandbox test only.
- Verifier: ECARTS(2). W1-W5, W7 met. W6: the hostile corpus through the child was missing (added, above); `pnpm
e2e:avatar` « unchanged » not run: the script starts a worker against the DEV stack, which §16.11 forbids without
the owner, so it stays the owner's decision (the avatar loop is unchanged: `job_loop` 11 tests, and the
verification mode leaves avatar and purge rows untouched, e2e case f). W8: gates recorded below.
Gates on the final HEAD: see the closing line of this section.
Choices for the owner: worker codes, attempt limit five, lease 10 minutes, verdict cap 4 MiB, service name
`worker-verify`, the shared `brk`, and that an object larger than the policy is passed without bytes (named
+1 -1
View File
@@ -253,7 +253,7 @@ unchanged.
- Child `faunosteo-worker verify`: same sandbox as `decode` (empty
environment, one thread, no core dump, the seccomp allowlist) with its own
limits: framed stdin input up to 12 MiB, `RLIMIT_AS` 1 GiB, `RLIMIT_CPU`
60 s, 90 s deadline, verdict output up to 4 MiB (the SQL cap). It runs the
60 s, 90 s deadline, verdict output up to 3 MiB (under the SQL cap of 4 MiB on `jsonb::text`). It runs the
core's `compute_verdict` and writes the verdict JSON; a failed verdict is
still a normal exit. The seccomp derivation of 2026-11-01 traced `brk` in
the verify child at the caps (musl mallocng growing its heap): added to the