How to Fix 'Supabase RLS Disabled in Public'
When Supabase flags 'RLS Disabled in Public', any person on the internet who grabs your public project URL and anon key from DevTools can read, edit, or wipe every single row in that table via PostgREST.
AI tools often generate raw CREATE TABLE statements in SQL migrations without adding ALTER TABLE ... ENABLE ROW LEVEL SECURITY, or they disable RLS during debugging when a query returns an empty array and forget to re-enable it.
- Full public dump of customer emails, waitlist signups, private notes, or invoices
- Unauthenticated attackers can INSERT spam rows or DELETE your entire table
- Trivially exploitable using a 3-line fetch() call to /rest/v1/<table_name>
Vulnerable Pattern vs. Production Fix
CREATE TABLE public.user_projects (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
user_id uuid NOT NULL REFERENCES auth.users(id),
name text NOT NULL,
secret_notes text
);
-- DANGER: PostgREST exposes public.user_projects to the anon key with ZERO restrictions!ALTER TABLE public.user_projects ENABLE ROW LEVEL SECURITY;
REVOKE ALL ON TABLE public.user_projects FROM anon;
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE public.user_projects TO authenticated;
CREATE POLICY "user_projects_owner_all"
ON public.user_projects
FOR ALL
TO authenticated
USING ((SELECT auth.uid()) = user_id)
WITH CHECK ((SELECT auth.uid()) = user_id);
CREATE INDEX IF NOT EXISTS idx_user_projects_user_id ON public.user_projects(user_id);Copy-Paste AI Fix Prompt (Cursor · Lovable · Bolt · Claude Code)
Fix all "Supabase RLS Disabled in Public" warnings in this project: 1. Inspect every SQL migration and table in the public schema. 2. Create a new Supabase migration that runs ALTER TABLE public.<table_name> ENABLE ROW LEVEL SECURITY on every single public table. 3. Add least-privilege policies using (SELECT auth.uid()) = user_id for private user tables, read-only policies for billing/subscription tables, and insert-only policies for public waitlist/contact tables. 4. Revoke blanket anon privileges where unauthenticated reads are not required, and verify client queries still work for logged-in users.
How to Verify Your Fix Worked
- 1Run SELECT tablename, rowsecurity FROM pg_tables WHERE schemaname = 'public' AND rowsecurity = false; — it must return 0 rows.
- 2Refresh Supabase Dashboard -> Advisors -> Security Advisor and confirm the error disappears.
- 3Test fetching /rest/v1/<table> in curl with ONLY your anon key and confirm it returns [] or 401/403.
Frequently Asked Questions
Why did my app return empty arrays right after enabling RLS?
Enabling RLS activates 'default deny' — no rows are visible until you add explicit CREATE POLICY statements for SELECT, INSERT, UPDATE, or DELETE.
Is my Supabase anon key supposed to be secret?
No, the anon key is intentionally public in browser apps. Security comes strictly from PostgreSQL Row Level Security policies and server-only service_role usage.
What if a table is only accessed by my backend server?
Still enable RLS on the table and create zero anon/authenticated policies (or move the table out of the public schema). Your server-side service_role key bypasses RLS while browsers remain blocked.