Files
faunosteo/.claude/audits/2026-11-02-avatar-e2e-sandbox-only.md
bchanot d3dfd03213 test(supabase): avatar e2e clients refuse HTTP redirects
The suite's supabase-js clients followed redirects by default, so a 3xx
from the sandbox gateway would have carried the apikey header to another
origin. `noRedirectFetch` (`redirect: 'error'`) is passed as `global.fetch`
of both client factories; a regression test with two loopback servers
proves REST, auth and Storage calls stop at the 302. Live proof j and a
second 5/5 run are in the audit log; no production client changes.
2026-11-02 11:22:51 +01:00

11 KiB

Audit log — pnpm e2e:avatar on develop reaches the sandbox only (2026-11-02)

Branch bugfix/avatar-e2e-sandbox-only (off develop 6287e5b). Contract .claude/tasks/contracts/2026-11-02-avatar-e2e-sandbox-only-0240.md, plan .claude/tasks/plans/2026-11-02-avatar-e2e-sandbox-only-0215.md (revision 3). Every live command below was run by the orchestrator, from the bugfix worktree by absolute path (W=…/scratchpad/bugfix-avatar), never through a bare pnpm, never from the main checkout (which still holds the old DEV runner). Raw traces and outputs stay in the session scratchpad (…/scratchpad/proofs/), not in the repository.

Pre-flight (read-only)

  • Docker: context default, endpoint unix:///run/user/1000/docker.sock, DOCKER_HOST set to that same socket. No docker context pointing elsewhere.
  • Proxy variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY, their lower-case forms, NODE_USE_ENV_PROXY, npm_config_proxy, npm_config_https_proxy, GLOBAL_AGENT_HTTP_PROXY): none set in the shell; every proof below also unsets them explicitly (env -u …).
  • scripts/avatar-e2e.sh absent in $W; package.json alias = bash scripts/db-sandbox.sh avatar-e2e.
  • Old DEV runner container faunosteo_worker_e2e: absent.
  • DEV containers supabase_*_faunosteo (8), all running, StartedAt 2026-10-28T14:45:28/29Z (recorded before; identical after every proof, see "After").
  • Sandbox before: the V1-2 session's stack (db 57432, auth 57999, rest 57300, storage 57500, mail 57025, all on 127.0.0.1, no gateway, no worker), network faunosteo_dbsandbox_net (bridge, 5 containers), no Docker volume named faunosteo_dbsandbox*.
  • Shared image faunosteo_worker:dev before: sha256:b32319b9… (V1-2 build of 2026-11-01 22:59).
  • No concurrent db-sandbox, vitest or playwright process.

Static criteria (contract 1-4, 8)

# Oracle Result
1 runner deleted, no line invokes it (the two "removed" mentions excluded) DEV_RUNNER_GONE
2 alias, bash -n, dispatcher line ALIAS_OK
3 suite identical to V1-2 once the noRedirectFetch lines are dropped (owner-gated, see below); db-sandbox.sh blocks 47-52, 58-61, 255, 270-332, 342-359 verbatim; no cmd_verify_e2e / cmd_sheet_assets_e2e BLOCKS_IDENTICAL
4 no supabase status, 54321, supabase_kong, supabase_db_faunosteo, supabase_network_faunosteo in the runner or the suite NO_DEV_IDS
8 corepack pnpm -s typecheck && lint in $W (after pnpm wasm:build, the git-ignored packages/core-wasm/pkg being absent in a fresh worktree) STATIC_GREEN

Refusal proofs (strace -f -e trace=connect,sendto,sendmsg, child processes followed)

Positive control: the same filter on curl http://127.0.0.1:9/ shows 1 AF_INET connect. Keys in c, d, e, h, i are forged unsigned JWTs (base64url(header).base64url(payload).x), never the sandbox secrets, never DEV keys. Criterion: no AF_INET / AF_INET6 line unless stated.

Case Setup Result AF_INET lines
a bash $W/scripts/db-sandbox.sh avatar-e2e, FAUNOSTEO_SANDBOX_DIR = empty dir db-sandbox: not running (pnpm db:sandbox up fresh), rc 1, no container, dir still empty 0
b the suite (vitest binary, vitest.e2e.config.ts), no environment throws avatar e2e: run it through pnpm e2e:avatar, on the sandbox stack only, rc 1 0
c SUPABASE_URL=http://127.0.0.1:54321, AVATAR_E2E_DB_CONTAINER=supabase_db_faunosteo, two keys iss: supabase-demo throws (same message) 0
d sandbox URL, keys iss: db-sandbox, container supabase_db_faunosteo throws 0
e sandbox URL and container, anon key whose payload is not JSON throws 0
i sandbox URL and container, anon iss: db-sandbox + service iss: supabase-demo, then the swap (i1, i2) throws, both orders 0, 0
h nothing listening on 57800 (ss -ltn: 0), sandbox URL and container, two forged iss: db-sandbox keys the guard passes; beforeAll fails on createUser: fetch failed (the refused connect), 5 tests skipped, rc 1 1: connect(127.0.0.1:57800)
f sandbox up, image present, 127.0.0.1:57800 held by python3 -I -m http.server db-sandbox: port 127.0.0.1:57800 is already in use: free it, nothing was started, rc 1, no gateway, no worker, no worker.* env file 1: the /dev/tcp probe connect(127.0.0.1:57800) = 0 (the exception accepted by the owner)

Reading of h (brief §3): the issuer check routes the run to the sandbox, it is not a signature check and not an authentication: whoever holds 127.0.0.1:57800 receives the keys the environment supplies. Nothing else is contacted.

Setup and positive run

  • corepack pnpm --dir $W worker:image: faunosteo_worker:dev now sha256:d841660a… (develop's crates; cached build dated 2026-11-01 01:38). The V1-2 build b32319b9… is no longer listed: the V1-2 session rebuilds it before its next worker run.
  • bash $W/scripts/db-sandbox.sh down (identity checked first: 5 faunosteo_dbsandbox_* containers on faunosteo_dbsandbox_net, no volume, no concurrent process), then up fresh from the branch: develop migrations and seeds, no key in the output.
  • Positive run, once, under strace, with hostile exports in the environment: SUPABASE_URL=http://127.0.0.1:54321, forged iss: supabase-demo keys, AVATAR_E2E_DB_CONTAINER=supabase_db_faunosteo, SUPABASE_NETWORK=supabase_network_faunosteo, SUPABASE_INTERNAL_URL=http://supabase_kong_faunosteo:8000, WORKER_IMAGE=faunosteo_worker:local (the old runner's knobs), proxies unset → bash $W/scripts/db-sandbox.sh avatar-e2e: 5/5 passed (15 s), rc 0, == worker up (faunosteo_worker:dev, run, via faunosteo_dbsandbox_gateway).
  • strace of the run: 4 AF_INET connects, all 127.0.0.1:57800 (1 probe ECONNREFUSED before the gateway existed, 3 from the suite); 0 to :54321 / :54322 / a LAN address; 0 AF_INET6.
  • Watcher during the run (filtered templates only, never a raw docker inspect): docker port faunosteo_dbsandbox_gateway 8000/tcp = 127.0.0.1:57800; gateway and worker networks = faunosteo_dbsandbox_net only; worker SUPABASE_URL=http://faunosteo_dbsandbox_gateway:8000; worker env names = PATH SSL_CERT_FILE SUPABASE_SERVICE_ROLE_KEY SUPABASE_URL WORKER_ID WORKER_POLL_SECONDS WORKER_QUARANTINE_GRACE_SECONDS WORKER_SWEEP_SECONDS; image faunosteo_worker:dev = d841660a…; user nonroot, read-only rootfs, CapDrop=[ALL], no published port.
  • Worker log events: worker_start 1, job_completed 3, job_rejected 3, child_rejected 3, sweep_done 4, token_expires_soon 1 (the sandbox key's lifetime); no DEV name, no key (eyJ count 0 in every output).

After

  • Gateway and avatar worker removed by the EXIT trap; no worker.* env file left in the state dir.
  • Final bash $W/scripts/db-sandbox.sh down: 0 faunosteo_dbsandbox_* container; the state dir keeps only rehearsal/ and upgrade-base/ (pre-existing).
  • DEV containers: same 8 StartedAt values as before. No HTTP request to DEV at any point (no connect to 54321/54322 in any trace).

What the isolation rests on (not the issuer check)

  • The worker's target is fixed to http://faunosteo_dbsandbox_gateway:8000 in a 600 env file removed once the container started (scripts/db-sandbox.sh start_worker); the worker's HTTP client sets max_redirects(0) and proxy(None) (crates/worker/src/http.rs:31,33).
  • The gateway's upstreams are the sandbox containers by name; location / { return 404; }; published on 127.0.0.1:57800 only, checked after start (docker port).
  • The sandbox keys are signed with a secret DEV does not hold; the suite builds its clients on the constant http://127.0.0.1:57800, never on the env URL; psql on the constant container.
  • scripts/dev-env.sh:23 exports FAUNOSTEO_DEV_API_URL into every child of db-sandbox.sh; nothing in the runner or the suite reads it. NET is a plain bridge (it can route to the host): the proofs above show nothing uses that route.

Redirects refused (owner condition at the checkpoint, 2026-11-02)

The former residual LOW is closed on this branch: tests/e2e/noRedirectFetch.ts wraps the global fetch with redirect: 'error' (set after the caller's init, so nothing restores follow); the suite's anonClient() and serviceClient() pass it through global.fetch, which supabase-js hands to its auth, REST and Storage calls (raw to auth-js, through fetchWithAuth for REST and Storage; neither layer sets redirect, retries reuse the wrapper). No production client changes (packages/supabase/src, apps/app/src untouched since 6287e5b). Security gate nuance that motivated it: on a cross-origin redirect undici drops Authorization but keeps supabase-js's apikey header.

  • Regression test packages/supabase/tests/no-redirect-fetch.test.ts (in pnpm --filter @faunosteo/supabase test:run, 12 files / 131 tests green): two node:http servers, the origin answers every request with 302 towards the target; REST, auth and Storage calls all error, the target receives nothing, every origin request carries apikey: test-key; the control (plain fetch, default follow) reaches the target at /landed. Negative control by the executor: with follow in the wrapper, 3 of the 4 cases fail.
  • Live proof j (strace, same harness as a-i): a Python 302 listener on 127.0.0.1:57800 (Location: http://127.0.0.1:57801/landed) and a recording target on 57801. Control: curl -L lands on 57801 (1 hit). The suite with forged iss: db-sandbox keys: 1 connect to 127.0.0.1:57800, 0 to 57801, 0 hit on the target, createUser: fetch failed, 5 tests skipped, rc 1 (fails closed).
  • Positive run 2, fresh sandbox from the branch, under strace, proxies unset: 5/5, 4 connects all to 127.0.0.1:57800, 0 key in the output, gateway and worker removed, final down. DEV StartedAt digest identical to the pre-flight.

Residual LOW (owner brief §3; kept as is, V1-2 first then port)

  • A proxy would be honoured by Node's fetch only with NODE_USE_ENV_PROXY=1 (unset here, unset by every proof).
  • worker_env is read by the EXIT trap before start_worker assigns it (an inherited value would be rm -f'd on an early die).
  • Every docker call follows DOCKER_HOST / the current context (both local here).
  • SB_SEED_PW / rotated seed password not ported (develop's sandbox suite signs in with the seed password); the avatar suite itself creates its two accounts with a random password.

Hand-off

  • V1-2 session: rebuild faunosteo_worker:dev (pnpm worker:image in its worktree) and run pnpm db:sandbox up fresh before its next sandbox run (the develop secrets file carries no SB_SEED_PW; V1-2's load_secrets refuses it: fails closed).
  • Copies that still reach DEV through pnpm e2e:avatar: the main checkout /home/bchanot/Documents/faunosteo (feature/v1-1-clients-animals, merged) and the worktree old-958228a. Agents never run them; their fate is the owner's call.