Skip to content

security(db): enable RLS on all tables + harden functions#6

Open
StockerMC wants to merge 1 commit into
mainfrom
security/enable-rls
Open

security(db): enable RLS on all tables + harden functions#6
StockerMC wants to merge 1 commit into
mainfrom
security/enable-rls

Conversation

@StockerMC
Copy link
Copy Markdown
Owner

Summary

Captures, as a reproducible migration, the security hardening already applied to the live Supabase DB. Previously RLS was disabled on all 18 public tables — and because the anon key ships in the browser bundle, any visitor could read/write every table directly via PostgREST, including OAuth credentials.

What changed (backend/data/enable_rls_security.sql)

  1. Enable RLS on all 18 public tables (default-deny for anon).
  2. Minimal anon policies for surfaces the frontend uses directly:
    • creator_videos, product_creator_matches — SELECT
    • reel_interactions — SELECT + DELETE
    • waitlist — INSERT only (emails stay non-readable)
  3. Pin search_path=public on the 4 SECURITY-relevant functions.

Everything else becomes server-only — API routes use the service-role key, which bypasses RLS.

Verification (live DB, anon-role impersonation)

Table anon access
creator_videos 23 rows ✅
product_creator_matches 31 rows ✅
youtube_shorts 1 row ✅
creator_tokens / shopify_oauth_tokens / partnerships / companies 0 — blocked 🔒

Supabase security advisor: all ERROR-level lints (RLS-disabled + sensitive-columns-exposed) cleared.

Known follow-ups (not blockers)

  • reel_interactions DELETE and waitlist INSERT use (true) predicates — inherent to the demo having no real per-user auth yet (getCurrentUser() is mocked). Tighten once Supabase Auth is wired in.

…function search_path

Captures the security hardening already applied to the live Supabase DB
(2026-05-30) as a reproducible migration:
- Enable RLS on all 18 public tables. Previously RLS was OFF everywhere and
  the anon key ships in the browser bundle, so anyone could read/write every
  table directly via PostgREST — including creator_tokens and
  shopify_oauth_tokens (OAuth credentials).
- Add minimal anon policies for the surfaces the frontend uses directly
  (creator_videos / product_creator_matches SELECT; reel_interactions
  SELECT+DELETE; waitlist INSERT-only).
- Pin search_path=public on the four SECURITY-relevant functions.

Server routes use the service-role key (bypasses RLS) so they are unaffected.
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
maatchaa Ready Ready Preview, Comment May 31, 2026 3:21pm

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