Repository navigation
fix(security): enable RLS on exposed tables (competitors, topics, prompt_volumes, jobs) - #250
Merged
Merged
Conversation
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()).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Four tables have shipped since
00001with Row Level Security disabled andGRANT ALLto theauthenticatedrole 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)
service_rolekey (server/src/config/supabase.js,web/src/lib/supabase/admin.ts), which bypasses RLS — unaffected.SECURITY INVOKERRPC is starved (confirmed: zero matches across allpublicfunctions).jobsandprompt_volumesare never read through the cookie-based authenticated client (server-only), so they get RLS with no policy — the authenticated/anon REST surface is denied whileservice_rolekeeps working.competitorsandtopicsare read/written by Server Actions through the authenticated client, so they get org-membership-scoped policies (SELECT/INSERT/UPDATE/DELETE) mirroring the existingcontent_opportunities: member selectpattern (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):topicscompetitorsjobsprompt_volumesThe identical policy on
content_opportunitieswas 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(migrationenable_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)