Skip to content

fix(security): enable RLS on exposed tables (competitors, topics, prompt_volumes, jobs) - #250

Merged
gkhngyk merged 1 commit into
mainfrom
fix/enable-rls-exposed-tables
Jun 13, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/enable-rls-exposed-tables

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Four tables have shipped since 00001 with Row Level Security disabled and GRANT ALL to the authenticated role with no policies: competitors, topics, prompt_volumes, jobs. With RLS off, any holder of the public anon key could read or write every organization's rows directly via PostgREST, bypassing the application (an IDOR-class exposure flagged by Supabase's own advisor).

This enables RLS on all four.

Why it's safe (verified against prod, read-only)

  • Server / worker / MCP use the service_role key (server/src/config/supabase.js, web/src/lib/supabase/admin.ts), which bypasses RLS — unaffected.
  • No SQL function references any of these tables, so no SECURITY INVOKER RPC is starved (confirmed: zero matches across all public functions).
  • jobs and prompt_volumes are never read through the cookie-based authenticated client (server-only), so they get RLS with no policy — the authenticated/anon REST surface is denied while service_role keeps working.
  • competitors and topics are read/written by Server Actions through the authenticated client, so they get org-membership-scoped policies (SELECT/INSERT/UPDATE/DELETE) mirroring the existing content_opportunities: member select pattern (brand_id → brands → profiles → auth.uid()). Member-level (no role gate) to preserve current in-org behavior; only cross-org access is blocked.

Verification (live, on the production DB)

Impersonating a real authenticated user inside a BEGIN … ROLLBACK (nothing persisted):

Table Before (RLS off) After
topics 224 (all orgs) 1 (own org)
competitors 186 (all orgs) 10 (own org)
jobs leaking 0 (denied to authenticated)
prompt_volumes leaking 0 (denied)

The identical policy on content_opportunities was confirmed to already enforce for the same user (9 of 901 rows), proving the pattern.

Deployment

Already applied to the production project via apply_migration (migration enable_rls_exposed_tables), matching the established workflow for the last several migrations (MCP-applied + numbered file committed here). Rollback is instant if ever needed: ALTER TABLE … DISABLE ROW LEVEL SECURITY / DROP POLICY.

Type of change

  • fix — security (RLS / missing authorization)

competitors, topics, prompt_volumes and jobs have shipped since 00001 with
Row Level Security disabled and GRANT ALL to the authenticated role, so any
holder of the public anon key could read/write every org's rows directly via
PostgREST, bypassing the app.

Enable RLS on all four. Server/worker code uses the service_role key (bypasses
RLS) so it is unaffected, and no SQL function references these tables. jobs and
prompt_volumes are never touched by the authenticated client (server-only), so
they get RLS with no policy. competitors and topics are read/written by Server
Actions through the authenticated client, so they get org-membership-scoped
policies mirroring the existing content_opportunities pattern
(brand_id -> brands -> profiles -> auth.uid()).
@gkhngyk
gkhngyk merged commit da817c2 into main Jun 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant