Skip to content
Frontend

Avoiding Row-Level Security (RLS) pitfalls in Supabase AI apps

AI-generated frontend and Supabase backend applications often overlook Row-Level Security (RLS), leading to data leaks and unauthorized access. This guide breaks down 6 common RLS security failure scenarios, pre-launch audit steps, and CI persistence solutions.

DEV.to #vibecoding
SupabasePostgresLovableBoltCursorClaude Code

Added 2026-11-07 · originally published Fri, 06 Nov 2026 02:00:44 +0000


Key points

  • Check for tables without RLS enabled: AI-generated SQL migration scripts do not enable row-level security by default, so you must manually run alter table ... enable row level security.
  • Avoid using USING (true) or WITH CHECK (true): This exposes all rows to logged-in or anonymous users or allows spoofing other users' user_id.
  • Bind ownership and optimize auth.uid(): Use (select auth.uid()) = user_id wrapped in a subquery in policies, and store permission data in app_metadata rather than user_metadata, which users can edit.
  • Watch out for views, functions, and storage vulnerabilities: PostgreSQL 15+ views need security_invoker = true set, and never use the service role key which bypasses RLS in client-side code.
  • Perform pre-launch audits: Inventory tables without RLS enabled, review policies from an attacker's perspective, and run cross-read/write tests with two real users.

Pitfalls

  • SQL migration scripts missing RLS enablement, causing tables to be publicly exposed
  • Using USING (true) or WITH CHECK (true), leading to full-table data leaks or allowing forged user IDs
  • Storing sensitive authorization data, such as user roles, in user_metadata which users can edit themselves
  • Views and security definer functions unintentionally bypassing RLS restrictions
  • Directly using the high-privilege service_role key in client-side code (browser-side)
.cursorrules
- Ensure all tables created via migration scripts have `enable row level security` enabled
- Do not use overly permissive security policies like `using (true)` or `with check (true)`
- All INSERT/SELECT policies must bind `auth.uid()` to `user_id`
- Permission and role checks must use `app_metadata` instead of `user_metadata`
- Do not use the `service_role` key in client-side code
Copy-ready prompt
When using [AI tool name] to write Supabase databases and migration scripts for [project name], you must strictly follow these RLS (Row-Level Security) rules: 1. All newly created tables must explicitly execute enable row level security; 2. Never write permissive policies using (true) or WITH CHECK (true); 3. INSERT and SELECT policies must explicitly bind ownership using (select auth.uid()) = user_id; 4. Authorization data must be stored in app_metadata, and never use user_metadata for permission checks; 5. Never use the service_role key in client-side code.
#Supabase#RLS Security#Backend Security#AI Coding Pitfalls
Preventing AI from exposing Supabase service keys in frontend code

When AI tools encounter frontend queries blocked by RLS, they often incorrectly use the service-role key to bypass security restrictions. This exposes the key directly to browser visitors and risks database tampering.

Elevating AI frontend quality and avoiding chaos

Effectively reduce the problem of AI generating ugly or buggy frontend code by choosing the right AI tools, configuring MCP services (such as Playwright, Figma Dev Mode, and Chrome DevTools) to get real context and browser validation, and writing project rule files (such as AGENTS.md or .cursor/rules).

Boost frontend page design and aesthetics with AI skills

By installing specialized design and aesthetics skills, you can standardize AI's color palettes, typography, interaction guidelines, spacing, and hierarchy, helping you move away from generic, cookie-cutter template results.

Found this useful? Get daily updates on Telegram or X.

Found this useful? Buy me a coffee ☕

nebu.life is free to use. If it helped you, a small tip keeps it going. Payments go straight to the author's personal account; this site never handles any funds.

Summarized by AI from the original source - refer to the original post for details. Copyright belongs to the original author.

nebu.lifeNebula AI Playbook · Daily AI use cases, prompts and prices

Content is collected daily from public sources and summarized with AI. Every entry links to the original, and copyright stays with the original authors. Spotted an error or a rights issue? Let us know via the contact page.

Last updated 2026-11-14 07:16 (Beijing time)