Create polished demo videos without editing skills. Mac/Windows/Linux
Revoke inherited feedback client privileges and add rollback access checks
webadderall12a919241aff
diff --git a/services/supabase/README.md b/services/supabase/README.mdindex a0d01030..40d425ce 100644--- a/services/supabase/README.md+++ b/services/supabase/README.md@@ -2,7 +2,7 @@Before releasing feedback submission:-1. Apply `migrations/202609230001_feedback.sql` and then `migrations/202609230002_feedback_limits.sql` in the configured Supabase project. If the first migration is already applied, apply only the second.+1. Apply `migrations/202609230001_feedback.sql` and then `migrations/202609230002_feedback_limits.sql` in the configured Supabase project. Apply `migrations/202610030001_feedback_access.sql` after both, including on existing deployments; it revokes inherited client table privileges while preserving owner reads and server inserts.2. Deploy the `submit-feedback` Edge Function from the repository root with the Supabase CLI: `supabase functions deploy submit-feedback --workdir services --project-ref YOUR_PROJECT_REF`. The function explicitly validates the bearer token with `auth.getUser` before parsing or storing feedback. The function configuration disables only the gateway's JWT check, not the function's authentication.3. Use the project's built-in `SUPABASE_URL` and `SUPABASE_SERVICE_ROLE_KEY` secrets for the function. Never put a service-role key in the desktop app.@@ -15,3 +15,9 @@ On submission, the modal captures up to 100 recent renderer warnings/errors (2,0A local demo account can preview the form but cannot submit without a real Supabase session. Failed submissions retain the draft in memory; closing and reopening the same modal keeps it, but restarting the app does not. The function cleans up failed uploads on a best-effort basis. Periodically remove unattached objects left by interrupted sessions through the Storage API, and prune old `feedback_daily_usage` rows after their UTC day has ended.Unit tests exercise the server handler with an injected storage/auth backend. `tests/feedback_limits.sql` verifies the migration's quotas and permissions in a disposable database with the migrations applied; it rolls back its test data. Live deployment and end-to-end Supabase uploads must be checked separately before release.++## Access verification++Run `checks/feedback-quota-access.sql` as postgres after all feedback migrations in a disposable Supabase database. It uses an existing user with no feedback usage today and rolls back test data. It checks server-only quota access, authenticated attachment-upload denial for the feedback bucket, client report write denial, anonymous read denial, and all three daily limits. The older `checks/feedback-access.sql` is only for testing migration 001 in isolation, before migration 002 removes direct client inserts.++Do not put real account IDs, project references, credentials, or operator setup status in this documentation.diff --git a/services/supabase/checks/feedback-access.sql b/services/supabase/checks/feedback-access.sqlnew file mode 100644index 00000000..54726d67--- /dev/null+++ b/services/supabase/checks/feedback-access.sql@@ -0,0 +1,47 @@+-- Baseline check for migration 001 only; migration 002 intentionally removes direct inserts.+-- Run as postgres in the SQL editor after applying migration 001.+-- Requires at least one existing auth user. All test data is rolled back.+begin;+select set_config('recordly.test_owner', (select id::text from auth.users limit 1), true);+select set_config('recordly.test_report', gen_random_uuid()::text, true);+select set_config('request.jwt.claim.sub', current_setting('recordly.test_owner'), true);+set local role authenticated;+insert into public.feedback_reports (id, title, subject, message)+values (current_setting('recordly.test_report')::uuid, 'Setup access check', 'other', 'Temporary test; transaction will roll back.');+do $$+begin+ if not exists (select 1 from public.feedback_reports where id = current_setting('recordly.test_report')::uuid) then+ raise exception 'Owner cannot read their feedback';+ end if;+ begin+ update public.feedback_reports set title = 'Unexpected update' where id = current_setting('recordly.test_report')::uuid;+ raise exception 'Unexpected authenticated update permission';+ exception when insufficient_privilege then null;+ end;+end $$;+select set_config('request.jwt.claim.sub', gen_random_uuid()::text, true);+do $$+begin+ if exists (select 1 from public.feedback_reports where id = current_setting('recordly.test_report')::uuid) then+ raise exception 'Cross-user feedback read allowed';+ end if;+ begin+ insert into public.feedback_reports (id, user_id, title, subject, message)+ values (gen_random_uuid(), current_setting('recordly.test_owner')::uuid, 'Spoof attempt', 'other', 'Must be rejected');+ raise exception 'Cross-user feedback insert allowed';+ exception when insufficient_privilege then null;+ end;+end $$;+reset role;+set local role anon;+do $$+begin+ begin+ perform 1 from public.feedback_reports;+ raise exception 'Anonymous feedback read allowed';+ exception when insufficient_privilege then null;+ end;+end $$;+reset role;+rollback;+select 'PASS: owner insert/read; update, cross-user read/write and anonymous read blocked; test data rolled back' as result;diff --git a/services/supabase/checks/feedback-quota-access.sql b/services/supabase/checks/feedback-quota-access.sqlnew file mode 100644index 00000000..23910dc2--- /dev/null+++ b/services/supabase/checks/feedback-quota-access.sql@@ -0,0 +1,71 @@+-- Run as postgres after migration 002. All quota changes are rolled back.+-- Uses an existing auth user with no usage today; no auth users are created.+begin;+do $$+declare account uuid;+begin+ select id into account from auth.users u where not exists (+ select 1 from public.feedback_daily_usage q where q.user_id=u.id and q.day=(now() at time zone 'UTC')::date+ ) limit 1;+ if account is null then raise exception 'Requires an existing user with no feedback usage today'; end if;+ perform set_config('recordly.quota_test_owner', account::text, true);+ if has_function_privilege('authenticated', 'public.reserve_feedback_quota(uuid,integer,bigint)', 'EXECUTE')+ or has_function_privilege('anon', 'public.reserve_feedback_quota(uuid,integer,bigint)', 'EXECUTE')+ or has_table_privilege('authenticated', 'public.feedback_daily_usage', 'UPDATE')+ or has_table_privilege('authenticated', 'public.feedback_reports', 'INSERT')+ or has_table_privilege('authenticated', 'public.feedback_reports', 'UPDATE')+ or has_table_privilege('authenticated', 'public.feedback_reports', 'DELETE')+ or has_table_privilege('anon', 'public.feedback_reports', 'SELECT') then+ raise exception 'Client can bypass server quotas';+ end if;+ if not has_function_privilege('service_role', 'public.reserve_feedback_quota(uuid,integer,bigint)', 'EXECUTE') then+ raise exception 'Server cannot reserve quota';+ end if;+ if public.reserve_feedback_quota(account,6,1) or public.reserve_feedback_quota(account,1,10485761)+ or public.reserve_feedback_quota(account,-1,0) then raise exception 'Submission bounds bypassed'; end if;+end $$;+-- Exercise this bucket under the client role, without rejecting unrelated bucket policies.+select set_config('request.jwt.claim.sub', current_setting('recordly.quota_test_owner'), true);+set local role authenticated;+do $$+begin+ begin+ insert into storage.objects (id, bucket_id, name)+ values (gen_random_uuid(), 'feedback-attachments', current_setting('recordly.quota_test_owner') || '/' || gen_random_uuid()::text || '/test.png');+ raise exception 'Client can upload feedback without reserving quota';+ exception when insufficient_privilege then null;+ end;+end $$;+reset role;+savepoint empty_usage;+do $$+declare account uuid := current_setting('recordly.quota_test_owner')::uuid;+begin+ for i in 1..5 loop+ if not public.reserve_feedback_quota(account,5,1) then raise exception 'Valid file quota rejected'; end if;+ end loop;+ if public.reserve_feedback_quota(account,1,1) then raise exception 'Daily file quota bypassed'; end if;+end $$;+rollback to savepoint empty_usage;+do $$+declare account uuid := current_setting('recordly.quota_test_owner')::uuid;+begin+ for i in 1..5 loop+ if not public.reserve_feedback_quota(account,1,10485760) then raise exception 'Valid byte quota rejected'; end if;+ end loop;+ if public.reserve_feedback_quota(account,1,1) then raise exception 'Daily byte quota bypassed'; end if;+end $$;+rollback to savepoint empty_usage;+do $$+declare account uuid := current_setting('recordly.quota_test_owner')::uuid;+begin+ for i in 1..10 loop+ if not public.reserve_feedback_quota(account,0,0) then raise exception 'Valid report quota rejected'; end if;+ end loop;+ if public.reserve_feedback_quota(account,0,0) then raise exception 'Daily report quota bypassed'; end if;+ if (select reports from public.feedback_daily_usage where user_id=account and day=(now() at time zone 'UTC')::date) <> 10 then+ raise exception 'Rejected request changed quota';+ end if;+end $$;+rollback;+select 'PASS: server-only quota access, upload bypass blocked, per-report bounds and all three daily limits; test data rolled back' as result;diff --git a/services/supabase/migrations/202609230001_feedback.sql b/services/supabase/migrations/202609230001_feedback.sqlindex da9434a1..bfdc0fa9 100644--- a/services/supabase/migrations/202609230001_feedback.sql+++ b/services/supabase/migrations/202609230001_feedback.sql@@ -1,4 +1,5 @@-- Apply to the Supabase project used by VITE_SUPABASE_URL before shipping feedback.+begin;create table public.feedback_reports (id uuid primary key,user_id uuid not null references auth.users(id) on delete cascade default auth.uid(),@@ -10,6 +11,7 @@ create table public.feedback_reports (attachments jsonb not null default '[]' check (jsonb_typeof(attachments) = 'array' and jsonb_array_length(attachments) <= 5));alter table public.feedback_reports enable row level security;+revoke all on public.feedback_reports from public, anon, authenticated;grant select, insert on public.feedback_reports to authenticated;create policy "Submit own feedback" on public.feedback_reports for insert to authenticated with check (user_id = auth.uid());create policy "Read own feedback" on public.feedback_reports for select to authenticated using (user_id = auth.uid());@@ -24,3 +26,5 @@ using (bucket_id = 'feedback-attachments' and (storage.foldername(name))[1] = au-- Allow owners to locate their uploads for cleanup; the bucket remains private.create policy "Read own feedback uploads" on storage.objects for select to authenticatedusing (bucket_id = 'feedback-attachments' and (storage.foldername(name))[1] = auth.uid()::text);++commit;diff --git a/services/supabase/migrations/202610030001_feedback_access.sql b/services/supabase/migrations/202610030001_feedback_access.sqlnew file mode 100644index 00000000..1392e759--- /dev/null+++ b/services/supabase/migrations/202610030001_feedback_access.sql@@ -0,0 +1,7 @@+-- Applies to already deployed databases; changing migration 001 alone is insufficient.+begin;+revoke all on public.feedback_reports from public, anon, authenticated;+grant select on public.feedback_reports to authenticated;+-- The authenticated Edge Function uses server-only insertion after quota reservation.+grant select, insert on public.feedback_reports to service_role;+commit;