StoicBuilder

HandbookIII the CastraDatabase access rules

IIIthe Castra, Stay in control

Database access rules

1 min readUpdated 28 November

In plain words

Database access rules, like Supabase's row-level security, make the database itself check which rows each user may read or change, whatever the app's code asks for.

Where you see it

Lovable apps talk to Supabase straight from the browser, using a key anyone can find in the page. If row-level security (RLS) is off on the notes table, that key reads every user's notes, and the Supabase table editor labels the table "Unrestricted".

supabase/migrations/20261201_notes_rls.sqldatabase
alter table notes enable row level security; create policy "Owners read their own notes"on notes for selectto authenticatedusing ((select auth.uid()) = user_id);
RLS on, one rule: each signed-in user reads only their own notes. Anything without a rule is refused.

What goes wrong

  1. Filtering in the app instead of the database

    An .eq("user_id", user.id) in your React code means nothing to someone with the public key and a terminal. The database has to refuse on its own.

  2. A policy that allows everything

    A policy with using (true) is a lock that's never closed. The warning disappears and the leak stays.

    create policy "allow all" on notes for all using (true);
  3. Testing only as yourself

    Everything looks right because you own all the test data. Sign in as a second user and try to open the first user's rows.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Enable row-level security on every table in the public schema, with separate select, insert, update and delete policies so users reach only their own rows. Then run Supabase's Security Advisor, and show me a test where a second user tries to read the first user's notes and gets nothing back.

Quick check

Sign in to earn +10 XP for it

Quill's code filters notes by the logged-in user, but RLS is off. Who can read every note?

Got a prompt that touches database access rules?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.