LeakPatrol › Guides

Supabase Storage upload fails with "new row violates row-level security policy"

By LeakPatrol · Updated 20 November 2026

You call supabase.storage.from('avatars').upload(path, file) and get StorageApiError: new row violates row-level security policy, often with status 403. Every file in Supabase Storage is a row in the storage.objects table, and that table has Row Level Security on. Uploading inserts a row, so it needs an INSERT policy on storage.objects, separate from any policies on your own tables. Here are the causes, most common first.

1. There's no INSERT policy for this bucket

A new bucket has no policies, so nobody can upload, not even signed-in users. Making the bucket public doesn't change that: "public" only means anyone can download files through the public URL. Add a policy that lets each user upload into their own folder:

create policy "Users upload to their own folder"
on storage.objects for insert
to authenticated
with check (
  bucket_id = 'avatars'
  and (storage.foldername(name))[1] = (select auth.uid())::text
);

2. The file path doesn't match the policy

With the policy above, the path must start with the user's id: `${user.id}/avatar.png`. Common mistakes:

3. You upload with upsert: true

An upsert may overwrite an existing file, so Storage also checks SELECT and UPDATE policies. If only INSERT exists, the first upload works and the second fails. Either upload with upsert: false and a unique file name, or add the matching policies:

create policy "Users read their own files"
on storage.objects for select to authenticated
using (bucket_id = 'avatars'
  and (storage.foldername(name))[1] = (select auth.uid())::text);

create policy "Users update their own files"
on storage.objects for update to authenticated
using (bucket_id = 'avatars'
  and (storage.foldername(name))[1] = (select auth.uid())::text);

4. The user isn't signed in yet

If the upload runs before the session has loaded, it's sent as anon and a policy to authenticated rejects it. Check (await supabase.auth.getSession()).data.session right before uploading.

5. Downloading, listing or signed URLs fail too

download(), list() and createSignedUrl() on a private bucket need a SELECT policy. Removing files needs a DELETE policy. If those calls return empty results or errors, it's the same fix with a different command.

What not to do

The same error on a normal table has other causes: see new row violates row-level security policy on tables.

A prompt to paste into Lovable, Bolt or Cursor

Uploading to the Supabase Storage bucket "avatars" fails with
"new row violates row-level security policy". Fix it safely:
1. List the current policies on storage.objects for this bucket.
2. Add INSERT, SELECT, UPDATE and DELETE policies for authenticated
   users, limited to files in a folder named after their auth.uid().
3. Make the upload path `${user.id}/`, with no leading slash
   and without the bucket name.
4. Only upload after the auth session has loaded.
Do not allow anon uploads, do not use with check (true), do not make
the bucket public, and do not use the service_role key in the frontend.

Want to check nothing else is exposed? LeakPatrol's free scan checks your live app for leaked keys, public files and other common mistakes in about a minute.

Check your app in a minute

Free, read-only, no sign-up. Every problem comes with a plain-English fix and a prompt for your AI tool.

Get the 10-point checklist

Every check we run on AI-built apps, with how to do each one yourself. Straight to your inbox.

Questions

Why does Supabase Storage upload say new row violates row-level security policy?

Every file is a row in storage.objects, which has RLS on. Uploading inserts a row, so you need an INSERT policy on storage.objects for that bucket. Policies on your own tables do not apply.

Does a public Supabase bucket allow uploads?

No. A public bucket only lets anyone download files through the public URL. Uploading, updating and deleting still need policies on storage.objects.

Why does the first upload work but the second fail?

Uploading with upsert: true can overwrite a file, so Storage also needs SELECT and UPDATE policies. Add them, or upload with upsert: false and a unique file name.

What path should I use with storage.foldername?

Start the path with the user id, like user-id/file.png, without a leading slash and without the bucket name. storage.foldername(name)[1] is then the user id the policy compares with auth.uid().

More guides