Vibe Code Guardian
← All posts

Supabase RLS Mistakes That Let AI-Built Apps Leak Data

Row Level Security is Supabase's main defence, but AI coding tools often skip it, misconfigure it, or assume the ORM handles it. Here are the specific RLS gaps that show up again and again in vibe-coded apps, and how to fix them before launch.

Aaron Allen·

Supabase RLS Mistakes That Let AI-Built Apps Leak Data

You asked Cursor to "add a posts table with RLS." It generated a migration, you ran it, and the app works. But does it actually stop one user from reading another's data?

In the last month of auditing vibe-coded apps, the same RLS gaps keep appearing. They are not obscure edge cases. They are the default output when you ask an AI to "secure this table" without specifying how.

The pattern: AI writes policies that look right but do not enforce

1. USING (true) - the open door

-- What the AI often generates
CREATE POLICY "Users can view posts" ON posts
  FOR SELECT USING (true);

This policy exists, so Supabase shows a green check in the dashboard. But USING (true) means "everyone can read everything." The AI treated the policy as a checkbox, not a condition.

Fix: Every SELECT policy needs a real predicate:

CREATE POLICY "Users can view own posts" ON posts
  FOR SELECT USING (auth.uid() = user_id);

2. Missing WITH CHECK on writes

USING controls reads. WITH CHECK controls writes. AI tools frequently omit the latter:

-- Incomplete - users can INSERT rows for other user_ids
CREATE POLICY "Users can insert posts" ON posts
  FOR INSERT WITH CHECK (auth.uid() = user_id);

-- Complete - also blocks UPDATE/DELETE on other users' rows
CREATE POLICY "Users can manage own posts" ON posts
  FOR ALL USING (auth.uid() = user_id)
  WITH CHECK (auth.uid() = user_id);

Without WITH CHECK, a malicious (or buggy) client can write user_id: "someone-else" and the row lands in their account.

3. Policies on the wrong table

AI often secures the parent table but forgets the join table. Example: a teams table with RLS, but team_members has none. A query like:

// This bypasses teams RLS entirely
const { data } = await supabase
  .from('team_members')
  .select('team_id, user_id')
  .eq('user_id', targetUserId);

Now the attacker knows every team the target belongs to. They can often reach the team's data through another unsecured path.

Rule: Every table that touches user data needs its own policies. No exceptions for "just a join table."

4. Relying on the client to filter

The AI adds .eq('user_id', user.id) to every query and calls it done. But the client is untrusted. If the policy is USING (true), removing that filter in the browser console exposes everything.

Test it: Open your app, open DevTools, run:

supabase.from('posts').select('*').limit(10)

If you see other users' data, your RLS is not working. Your client-side filter was the only thing holding the line.

5. Service role key in the frontend bundle

This is not strictly RLS, but it appears in the same audits. The AI puts SUPABASE_SERVICE_ROLE_KEY in a VITE_ or NEXT_PUBLIC_ variable. The key gets bundled, pushed to GitHub, deployed to Vercel. Now anyone can bypass all RLS.

Check: Search your repo for service_role or SUPABASE_SERVICE_ROLE. If it appears outside a server-only directory (Netlify Functions, Vercel Serverless, Cloudflare Workers), rotate the key immediately.

6. auth.uid() vs auth.jwt() confusion

auth.uid() returns the user's UUID. auth.jwt() returns the full JWT claims. AI sometimes writes:

-- Wrong for most cases
USING (auth.jwt()->>'role' = 'admin')

This works if you set custom claims via a hook. But most vibe-coded apps do not. So the policy evaluates to NULL (deny) or falls back to a weaker policy.

Use auth.uid() for ownership checks. Reserve auth.jwt() for actual role-based access where you have built the claims infrastructure.

7. No policy on storage.objects

You secured the avatars bucket in the dashboard. But the storage.objects table still has the default policy: USING (bucket_id = 'avatars') - which lets anyone with a valid token read every file in that bucket.

Add object-level policies:

CREATE POLICY "Users can read own avatars" ON storage.objects
  FOR SELECT USING (
    bucket_id = 'avatars' AND
    auth.uid() = (storage.foldername(name))[1]::uuid
  );

Assumes your upload path is user_id/filename.png. Adjust the folder index if your structure differs.

A 5-minute RLS audit you can run today

  1. List every table with enable row level security off:

    SELECT tablename FROM pg_tables
    WHERE schemaname = 'public'
    AND rowsecurity = false;
    
  2. For each table that has RLS, list its policies:

    SELECT schemaname, tablename, policyname, permissive, roles, cmd, qual, with_check
    FROM pg_policies
    WHERE schemaname = 'public';
    

    Look for qual = 'true' or missing with_check.

  3. Run the DevTools test above on your top 3 data tables.

  4. Search for service_role in your repo and frontend bundle.

  5. Check storage.objects policies for every bucket you use.

What Vibe Code Guardian checks

Our launch-readiness audit runs automated RLS validation across every table, plus manual review of policy logic, storage rules, and service-key exposure. The free surface check catches the most common gaps - missing policies, USING (true), and client-side keys - in under two minutes.

If you have vibe-coded a Supabase app and have not verified RLS end-to-end, assume it is leaking. The fixes above take minutes. A data breach takes months to unwind.


Built something with Cursor, Lovable, Bolt, or Replit? Run the free check or book the full audit - we will tell you exactly what is exposed and how to lock it down.

Want a developer to look at your app?

Built your app with AI tools? Run the free surface check yourself in a few minutes. Nothing to buy, and we never look at your app unless you run it.