fix(supabase): ceiling measured on bytes present in the bucket plus pending claims without bytes; confirm fails closed on an unsized object; cleartext host must start with a letter
Third audit (BLOCK 1): counting terminal rows while queued let begin spam pin the ceiling with declared sizes. The ceiling now sums storage.objects sizes of the bucket (whatever the row's state) plus the declared size of pending_upload rows whose quarantine object has not landed: a claim dies with its row, a present object counts whatever its row says, no full scan of the assets history. confirm_asset_upload treats an object without a size as upload_missing. pgTAP (plan 138): rejected rows without bytes weigh nothing, pending claims fill, superseded claims vanish, present bytes fill, unsized object refused. Worker: a single-label cleartext host must start with an ASCII letter (0X… hex forms refused, test added); STORAGE.md names the native-run search-domain residual.
This commit is contained in:
1 parent
369478576e
commit
273914d825
5 files changed
+48
-35
No files matched your search
@@ -2,7 +2,7 @@
|
||||
-- browser and worker RPCs, the purge queue. Every allowed path has its denial
|
||||
-- twin; the eight scenarios of the Step 8 brief are named in the descriptions.
|
||||
begin;
|
||||
select plan(137);
|
||||
select plan(138);
|
||||
|
||||
insert into auth.users (id, email) values
|
||||
('40000000-0000-0000-0000-00000000000a', 'alice-files@test.local'),
|
||||
@@ -475,8 +475,8 @@ select is(
|
||||
(select count(*) from private.object_purge_queue where object_name like 'profiles/40000000-0000-0000-0000-00000000000b/%' or object_name like 'quarantine/40000000-0000-0000-0000-00000000000b/%'),
|
||||
2::bigint, 'the cascade enqueues both keys of the deleted row'
|
||||
);
|
||||
-- Ceiling: 2048 rejected rows of 5 MiB do NOT count (purged bytes never ratchet
|
||||
-- the counter); 2048 in-flight rows of 5 MiB fill the 10 GiB.
|
||||
-- Ceiling = bytes present in the bucket + declared sizes of pending rows without bytes.
|
||||
-- 2048 rejected rows of 5 MiB (no object) weigh nothing.
|
||||
insert into public.assets (owner_id, kind, bucket_id, object_key, quarantine_key, status, declared_mime, declared_size, rejection_reason, created_at)
|
||||
select '40000000-0000-0000-0000-00000000000a', 'profile_avatar', 'avatars',
|
||||
'profiles/40000000-0000-0000-0000-00000000000a/' || g || '/avatar.webp',
|
||||
@@ -485,34 +485,42 @@ select '40000000-0000-0000-0000-00000000000a', 'profile_avatar', 'avatars',
|
||||
from (select gen_random_uuid() as g from generate_series(1, 2048)) s;
|
||||
set local role authenticated;
|
||||
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000c","role":"authenticated"}', true);
|
||||
select lives_ok($$ select public.begin_avatar_upload('image/jpeg', 1000) $$, 'rejected rows do not count toward the ceiling');
|
||||
select lives_ok($$ select public.begin_avatar_upload('image/jpeg', 1000) $$, 'rejected rows without bytes do not count toward the ceiling');
|
||||
reset role;
|
||||
-- 2048 pending rows of 5 MiB whose bytes have not landed are expected bytes.
|
||||
insert into public.assets (owner_id, kind, bucket_id, object_key, quarantine_key, status, declared_mime, declared_size, created_at)
|
||||
select '40000000-0000-0000-0000-00000000000c', 'profile_avatar', 'avatars',
|
||||
'profiles/40000000-0000-0000-0000-00000000000c/' || g || '/avatar.webp',
|
||||
'quarantine/40000000-0000-0000-0000-00000000000c/' || g || '/upload',
|
||||
'uploaded', 'image/jpeg', 5242880, now() - interval '2 hours'
|
||||
'pending_upload', 'image/jpeg', 5242880, now() - interval '2 hours'
|
||||
from (select gen_random_uuid() as g from generate_series(1, 2048)) s;
|
||||
set local role authenticated;
|
||||
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000c","role":"authenticated"}', true);
|
||||
select throws_ok($$ select public.begin_avatar_upload('image/jpeg', 1000) $$, 'P0001', 'storage_full', 'in-flight bytes fill the global ceiling');
|
||||
select throws_ok($$ select public.begin_avatar_upload('image/jpeg', 1000) $$, 'P0001', 'storage_full', 'declared sizes of pending uploads fill the ceiling');
|
||||
reset role;
|
||||
-- Deleted rows still count while their objects wait in the purge queue.
|
||||
update public.assets set status = 'deleted' where owner_id = '40000000-0000-0000-0000-00000000000c' and status = 'uploaded';
|
||||
-- Superseded or expired without bytes: the claim dies with the row (no pinning by begin spam).
|
||||
update public.assets set status = 'deleted' where owner_id = '40000000-0000-0000-0000-00000000000c' and status = 'pending_upload' and created_at < now() - interval '1 hour';
|
||||
set local role authenticated;
|
||||
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000c","role":"authenticated"}', true);
|
||||
select throws_ok($$ select public.begin_avatar_upload('image/jpeg', 1000) $$, 'P0001', 'storage_full', 'objects still queued for purge count toward the ceiling');
|
||||
select lives_ok($$ select public.begin_avatar_upload('image/jpeg', 1000) $$, 'scenario: rows that moved on without bytes weigh nothing, even while queued for purge');
|
||||
reset role;
|
||||
delete from private.object_purge_queue where object_name like '%/40000000-0000-0000-0000-00000000000c/%';
|
||||
-- Bytes present count whatever the row says: one 10 GiB object fills the ceiling.
|
||||
insert into storage.objects (bucket_id, name, metadata) values ('avatars', 'quarantine/40000000-0000-0000-0000-00000000000c/00000000-0000-0000-0000-00000000ffff/upload', '{"size":10737418240}');
|
||||
set local role authenticated;
|
||||
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000c","role":"authenticated"}', true);
|
||||
select lives_ok($$ select public.begin_avatar_upload('image/jpeg', 1000) $$, 'served purge entries free the ceiling');
|
||||
select throws_ok($$ select public.begin_avatar_upload('image/jpeg', 1000) $$, 'P0001', 'storage_full', 'bytes present in the bucket fill the ceiling whatever their row');
|
||||
reset role;
|
||||
update storage.objects set metadata = '{"size":1}' where name = 'quarantine/40000000-0000-0000-0000-00000000000c/00000000-0000-0000-0000-00000000ffff/upload';
|
||||
-- Carol's pending row (begun above): the object may not exceed the declared size.
|
||||
set local role authenticated;
|
||||
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000c","role":"authenticated"}', true);
|
||||
insert into pg_temp.ids select 'c1', id from public.assets where owner_id = '40000000-0000-0000-0000-00000000000c' and status = 'pending_upload';
|
||||
insert into storage.objects (bucket_id, name, metadata) values ('avatars', (pg_temp.row('c1')).quarantine_key, '{"size":4000}');
|
||||
insert into storage.objects (bucket_id, name, metadata) values ('avatars', (pg_temp.row('c1')).quarantine_key, '{}');
|
||||
select throws_ok($$ select public.confirm_asset_upload(pg_temp.id('c1')) $$, 'P0001', 'upload_missing', 'an object without a size is not confirmable (fail closed)');
|
||||
reset role;
|
||||
update storage.objects set metadata = '{"size":4000}' where name = (pg_temp.row('c1')).quarantine_key;
|
||||
set local role authenticated;
|
||||
select set_config('request.jwt.claims', '{"sub":"40000000-0000-0000-0000-00000000000c","role":"authenticated"}', true);
|
||||
select throws_ok($$ select public.confirm_asset_upload(pg_temp.id('c1')) $$, 'P0001', 'too_large', 'an object larger than the declared size is refused at confirm');
|
||||
reset role;
|
||||
update storage.objects set metadata = '{"size":1000}' where name = (pg_temp.row('c1')).quarantine_key;
|
||||
|
||||
Reference in new issue
Block a user