fix(supabase): security pass on the files foundation — ceiling counts live bytes only, confirm checks the account, null sha256 refused, browser RPCs one role; worker: cleartext only on loopback or a service name, no env proxy, key ownership cross-check, no library text in logs

Security audit (PASS, 2 MEDIUM + LOW): the global ceiling summed every
non-deleted row, so rejected uploads ratcheted it toward storage_full with no
disk used → in-flight rows by declared size, clean rows by byte_size, nothing
else (pgTAP: rejected rows do not count, in-flight rows do); confirm refuses a
deactivated account like begin; complete_avatar_job refuses a null sha256;
begin / confirm / remove granted to authenticated only. Worker: SUPABASE_URL
over http:// accepted only for loopback or a single-label Docker service
name; ureq proxy(None); the job's keys must embed its owner and asset ids;
backend_failure / claim_failed / sweep_failure lines carry the closed kind and
the HTTP status, never the library's error text. e2e: uuid shape checked
before the psql query. Contract revision 2 (oracle fixes).
This commit is contained in:
bchanot committed 2026-10-13 19:49:58 +02:00
1 parent 62eb4e5d82
commit cd2dbb3b79
11 files changed
+124 -31

No files matched your search

@@ -12,8 +12,8 @@ Step 8 = R1: `assets` table as the authority over user files, eight private buck
CHECK: pnpm --filter @faunosteo/supabase exec vitest run tests/db/pgtap.test.ts 2>&1 | grep -E "^ +Tests "
EXPECT: Tests 11 passed (11)
2. Exactly three policies are created by the migration (assets own-row SELECT, avatars read, avatars upload), the two Storage ones pin the bucket literal, and no UPDATE / DELETE policy exists on storage.objects.
CHECK: grep -c "^create policy" supabase/migrations/20261013100000_files_foundation.sql; grep -c "on storage.objects" supabase/migrations/20261013100000_files_foundation.sql; grep -cE "for (update|delete)" supabase/migrations/20261013100000_files_foundation.sql
EXPECT: 3 / 2 / 0
CHECK: grep -c "^create policy" supabase/migrations/20261013100000_files_foundation.sql; grep -c "on storage.objects" supabase/migrations/20261013100000_files_foundation.sql; grep -cE "^ for (update|delete)$" supabase/migrations/20261013100000_files_foundation.sql
EXPECT: 3 / 2 / 0 (the policy command clause is a line of its own; `select … for update` row locks inside functions are not policies)
3. The owner's column grant on assets excludes every lease and quarantine column.
CHECK: sed -n '/^grant select ($/,/to authenticated;/p' supabase/migrations/20261013100000_files_foundation.sql | grep -c "lock_token\|quarantine_key\|locked_at\|attempts"
EXPECT: 0
@@ -39,7 +39,7 @@ Step 8 = R1: `assets` table as the authority over user files, eight private buck
CHECK: grep -n "from('assets')" -A2 packages/supabase/src/assets.ts | grep -c "'\*'"; grep -rn "SERVICE_ROLE\|service_role" apps/app/src packages/supabase/src | grep -v database.types | wc -l
EXPECT: 0 / 0
11. The Node gate is green with the new tests (supabase package 37, app 300).
CHECK: pnpm --filter @faunosteo/supabase test:run 2>&1 | grep -E "^ +Tests "; pnpm --filter @faunosteo/app test:run 2>&1 | grep -E "^ +Tests "; pnpm typecheck > /dev/null 2>&1 && pnpm lint > /dev/null 2>&1 && echo GATE_OK
CHECK: pnpm --filter @faunosteo/supabase test:run 2>&1 | grep -E "^ +Tests "; pnpm --filter @faunosteo/app test:run 2>&1 | grep -E "^ +Tests "; ./node_modules/.bin/pnpm typecheck > /dev/null 2>&1 && ./node_modules/.bin/pnpm lint > /dev/null 2>&1 && echo GATE_OK
EXPECT: Tests 37 passed (37) / Tests 300 passed (300) / GATE_OK
12. The avatar transport refuses SVG by content and the UI section exists with the mockup's elements (change, save, cancel, remove, processing), strings in both dictionaries.
CHECK: grep -c "svg" apps/app/tests/unit/account.avatarTransport.test.ts; grep -c "'account.avatar\." apps/app/src/i18n/fr.ts; grep -c "'account.avatar\." apps/app/src/i18n/en.ts
@@ -55,4 +55,5 @@ Step 8 = R1: `assets` table as the authority over user files, eight private buck
EXPECT: every count ≥ 1
## FILE SCOPE
supabase/migrations/20261013100000_files_foundation.sql, supabase/tests/{001_schema,010_files_foundation}.sql, packages/supabase/{src,tests,package.json,vitest.e2e.config.ts}, apps/app/src/{account,components/account,components/shell,state/authStore.ts,i18n}, apps/app/tests, crates/worker/**, Cargo.toml, Cargo.lock, deny.toml, docker-compose.yml, scripts/avatar-e2e.sh, package.json, docs/**, CLAUDE.md, README.md, DEPLOY.md, CHANGELOG.md.
supabase/migrations/20261013100000_files_foundation.sql, supabase/tests/{001_schema,010_files_foundation}.sql, packages/supabase/{src,tests,package.json,vitest.e2e.config.ts}, apps/app/src/{account,components/account,components/shell,state/authStore.ts,i18n}, apps/app/tests, crates/worker/**, Cargo.toml, Cargo.lock, deny.toml, docker-compose.yml, scripts/avatar-e2e.sh, package.json, pnpm-lock.yaml (zod importer entry), docs/**, CLAUDE.md, README.md, DEPLOY.md, CHANGELOG.md, .claude/tasks/** (TODO plan and this contract), .claude/memory/** (registries).
- revision 2 (2026-10-13, after verifier pass 1 ECARTS(4), all oracle/scope): criterion 2 third grep anchored to the policy clause; criterion 11 lint via the binary path (the literal `pnpm lint` is intercepted by a sandbox output wrapper); FILE SCOPE widened to the lockfile and the tracking files.