GuardCue

Guide · Supabase

"New row violates row-level security policy": what it means and the safe fix

It means your database refused to save something, on purpose. Your app is not broken and nobody has broken in. Supabase checks a rule before adding a row, and no rule says this person may add it. The fix is to add the right rule. The one thing not to do is the fix your AI tool may suggest first: switching row level security off, which opens the table to everyone.

What does “new row violates row-level security policy” mean?

Row level security is the set of rules that decides who may read, add, change or delete each row in a table. Think of each table as a room with a guard at the door. This message is the guard saying no: someone tried to put something into the room, and none of the rules on the list allow it. The table name in the message, such as "profiles" or "orders", tells you which room.

Am I in danger?

No. This message means the protection is working; if anything it is too strict. The danger comes afterwards, from the wrong fix.

Why you should not switch row level security off

It makes the message go away, which is why AI tools sometimes suggest it. We tested it: on a table set up the way Supabase sets one up, we switched row level security off and then asked for the rows the way a stranger’s browser would, without signing in. We got another customer’s details back. With the rules switched off, the public key that sits in every Supabase website lets anyone read, change or delete that table. Supabase warns about exactly this as “RLS disabled in public”.

The five reasons it happens

We set up a test database the way Supabase does and caused this message each of these ways:

  1. There is no rule for adding rows. The table has a rule for reading, but none for saving. This is the most common one.
  2. The row belongs to someone else. The rule says people may only add rows for themselves, and the app filled in a different user, or left it empty.
  3. The person is not signed in yet. To the database, the app is acting as a stranger, so a rule for signed in users does not apply.
  4. The app saves and then reads the row back, with no rule for reading. Many apps do both in one step. Saving is allowed, reading it back is not, and the whole step fails with this same message. In our test, the same save worked the moment we stopped asking to read it back.
  5. The app saves or updates in one go, with no rule for updating. Then the message reads “new row violates row-level security policy (USING expression)”.

If the message names the table "objects", it is about uploading a file: the same kind of rule is missing on your storage bucket. Supabase’s own troubleshooting page says this usually means the database cannot read back the details of the file it just saved, which is reason 4 above.

The safe fix

Add rules that let each signed in person add, read and change only their own rows. Paste this into Lovable, Claude, Bolt, Cursor or whichever tool built your app:

My app shows "new row violates row-level security policy". Do not turn row level security off. For the table named in the message, add a policy that lets a signed in user insert a row only when its user_id equals auth.uid(), and a policy that lets them select their own rows. If the app saves or updates in one step, add an update policy for their own rows too. Make sure the app fills user_id with the signed in user and that the user is signed in before saving. Then list every policy on that table.

With those rules in our test, a signed in user could save their own profile, could not save one for another customer, and a stranger could neither save nor read anything. That is the result you want.

How do I know it worked?

GuardCue checks apps built with Claude, Lovable, Bolt or any other AI tool and explains what it finds in plain English. Related: row level security explained and “permission denied for table”.