fix(supabase): V1-2.1 close the second verifier and security findings

Save and submit lock the sheet before the version; change_note length and a
blank FR name answer closed codes; pgTAP for a capability refused to a
factorless account and the five remaining historical-sheet RPC refusals.
This commit is contained in:
bchanot committed 2026-10-28 18:44:00 +01:00
1 parent 4a829416c6
commit 961995804a
4 files changed
+47 -10

No files matched your search

+5 -1
View File
@@ -5,7 +5,7 @@
-- proven in packages/supabase/tests/sandbox/sheets.sandbox.ts, the seed owner's
-- factors on an upgraded stack in seed-owner-mfa.sandbox.ts.
begin;
select plan(36);
select plan(37);
insert into auth.users (id, email, email_confirmed_at) values
('d0000000-0000-0000-0000-000000000001', 'own@t.local', now()), -- owner
@@ -158,6 +158,10 @@ select lives_ok(
select lives_ok(
$$ select public.grant_catalog_right('d0000000-0000-0000-0000-00000000000c','catalog_reader','beta') $$,
'catalog_reader needs no note or factor');
-- a capability never goes to an account without a verified factor (§5.2)
select throws_ok(
$$ select public.grant_catalog_right('d0000000-0000-0000-0000-00000000000c','sheet_reviewer','partner','DVM verified') $$,
'P0001', 'grant.ineligible', 'a capability is refused to an account without a verified factor');
-- the owner cannot grant itself sheet_reviewer
select throws_ok(
$$ select public.grant_catalog_right('d0000000-0000-0000-0000-000000000001','sheet_reviewer','self','x') $$,
+1 -1
View File
@@ -155,7 +155,7 @@ insert into auth.users (id,email,email_confirmed_at) values ('e0000000-0000-0000
insert into public.anatomical_catalog_grants (user_id,grant_kind,reason,granted_by)
values ('e0000000-0000-0000-0000-0000000000cc','catalog_reader','beta','e0000000-0000-0000-0000-000000000001');
-- A catalogue reader sees the published version and its drawing; not the grants.
-- A catalogue reader sees the published version (the grants table rules are in 018).
set local role authenticated;
select pg_temp.act('e0000000-0000-0000-0000-0000000000cc', gen_random_uuid());
select is((select count(*) from jsonb_array_elements(public.list_official_catalog()) e
+19 -1
View File
@@ -8,7 +8,7 @@
-- ids created here, so the file also runs on a stack that already holds
-- sheets, rounds or a working copy.
begin;
select plan(78);
select plan(85);
-- Accounts: O owner, E admin + editor + publisher, V reviewer, V2 admin +
-- editor + reviewer (an author of a later round), V3 reviewer, R reader.
@@ -502,6 +502,17 @@ select throws_ok($$ select public.delete_sheet_asset(pg_temp.id('s13.asset')) $$
select throws_ok($$ select public.delete_sheet_asset((select id from public.anatomical_sheet_assets
where sheet_id = '503dc301-a8b1-50d4-9e44-0919b2fc2916' limit 1)) $$,
'42501', 'sheet.historical_read_only', 'the historical sheet''s drawing row is never deleted');
select throws_ok($$ select public.delete_anatomical_sheet('503dc301-a8b1-50d4-9e44-0919b2fc2916') $$,
'42501', 'sheet.historical_read_only', 'the historical sheet is never deleted through the RPC');
select throws_ok($$ select public.delete_sheet_version(pg_temp.id('h.v')) $$,
'42501', 'sheet.historical_read_only', 'the historical draft is never deleted through the RPC');
select throws_ok($$ select public.restore_anatomical_sheet('503dc301-a8b1-50d4-9e44-0919b2fc2916') $$,
'42501', 'sheet.historical_read_only', 'the historical sheet is never restored through the RPC');
select throws_ok($$ select public.create_sheet_draft('503dc301-a8b1-50d4-9e44-0919b2fc2916', null, 'x') $$,
'42501', 'sheet.historical_read_only', 'no draft is opened on the historical sheet');
select throws_ok($$ select public.confirm_sheet_asset_upload((select id from public.anatomical_sheet_assets
where sheet_id = '503dc301-a8b1-50d4-9e44-0919b2fc2916' limit 1)) $$,
'42501', 'sheet.historical_read_only', 'an editor never confirms a drawing of the historical sheet');
select throws_ok($$ select public.create_official_sheet('r17-s13', pg_temp.doc(null, 'reviewed')) $$,
'P0001', 'sheet.slug_taken', 'a slug already used by an official sheet');
select throws_ok($$ select public.create_official_sheet('Bad Slug', pg_temp.doc(null, 'reviewed')) $$,
@@ -522,6 +533,13 @@ select throws_ok($$ select public.save_sheet_draft(pg_temp.id('s13.v'), 1,
select throws_ok($$ select public.save_sheet_draft(pg_temp.id('s13.v'), 1,
jsonb_set(pg_temp.doc(pg_temp.id('s13.asset'), 'reviewed'), '{schema_version}', '3'), 'x') $$,
'23514', 'document.schema_version', 'save refuses another schema version');
select throws_ok($$ select public.save_sheet_draft(pg_temp.id('s13.v'), 1,
jsonb_set(pg_temp.doc(pg_temp.id('s13.asset'), 'reviewed'), '{description,fr}', '"n"'), repeat('x', 1001)) $$,
'P0001', 'invalid_input', 'a change note over 1 000 characters is invalid input, not a raw constraint error');
insert into pg_temp.k select 'blank', public.create_official_sheet('r17-blank',
jsonb_set(pg_temp.doc(null, 'reviewed'), '{name,fr}', '" "'));
select is((select name from public.anatomical_sheets where id = pg_temp.id('blank')), 'R horse',
'a blank FR name falls back to the EN name at creation');
select throws_ok($$ select public.create_sheet_draft(pg_temp.id('m3'), null, 'x') $$,
'P0001', 'draft.exists', 'one draft per sheet');
select public.publish_sheet_version(pg_temp.id('m3b.r'));