Guide
Why does my Supabase Storage upload fail with new row violates row-level security policy, and which policy is missing?
MondayMedic checks for common public mistakes. It is not a full security audit, and a good score does not mean your app is safe.
Check your live app first. Paste your app's public link into the free MondayMedic check. It reads only public pages and scripts, takes about a minute and needs no account. It flags Supabase tables the public key can read and secret keys in the browser. It does not read your storage policies, it does not change data, and it is not a full security audit.
The short answer
No policy on storage.objects lets this user write this file. A plain upload needs an INSERT policy. An upload with upsert: true also needs SELECT, and UPDATE to replace an existing file. Supabase Storage keeps a row for every file in the storage.objects table, and row level security is on for it. Supabase's docs say Storage "does not allow any uploads to buckets without RLS policies". When nothing matches, the upload comes back as a 403 with new row violates row-level security policy.
Fix it with a policy scoped to the bucket and to the user's own folder. Don't fix it with with check (true), by uploading with the service role key from the browser, or by making the bucket public (that doesn't help uploads anyway).
Which policy is missing for what I'm doing?
- Uploading a new file (
upload()with the defaultupsert: false):INSERTonly. Supabase: "the only RLS policy required for uploading objects is to grant theINSERTpermission". - Uploading with
upsert: true:INSERTplusSELECT, andUPDATEwhen the file already exists. Supabase's troubleshooting note explains that an upsert runs asINSERT ... ON CONFLICTwithRETURNING *, so without aSELECTpolicy the database can't return the new row and the whole upload fails with the same 403, even when yourINSERTpolicy is right. - Re-uploading to a path that already exists without upsert: no policy fixes this. Supabase returns an "already exists" error instead of the RLS one. Use a new file name, or turn on upsert and add the policies above.
- Downloading from a private bucket, listing, or making a signed URL:
SELECT. - Deleting:
DELETE, and the user must also be able to see the file through aSELECTpolicy.
Why does this happen in Lovable and Bolt apps?
The usual story: the AI builder adds an image or document upload and creates the bucket, but no policies on storage.objects, or a policy that doesn't match how the app names files. The common mismatches:
- No policy at all for the bucket.
- The path doesn't match the policy. The policy expects files under the user's id (
user-id/photo.png), but the app uploads to the bucket root or a fixed folder. - The user isn't signed in yet. The policy is
to authenticated, but the upload runs before sign-in finishes, or on a page where the session isn't loaded, so the request goes out as the anonymous role. - The code sets
upsert: trueand there's no matchingSELECTpolicy. - It worked in testing with the service role key, which bypasses RLS and hides missing policies until real users try it.
How do I see which storage policies I have?
Run this in the Supabase SQL editor:
select policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'storage' and tablename = 'objects'
order by cmd;
Look for a row with cmd = INSERT whose with_check names your bucket. If you use upsert, look for SELECT and UPDATE rows for the same bucket too. Then compare the policy's folder rule with the path your code actually uploads to.
What's the safe fix?
Upload each user's files into a folder named after their user id, and let policies check that folder. Replace user-uploads with your bucket name:
-- Upload into your own folder
create policy "own folder insert"
on storage.objects for insert to authenticated
with check (
bucket_id = 'user-uploads'
and (storage.foldername(name))[1] = (select auth.uid())::text
);
-- Read, list and sign URLs for your own files (also needed for upsert)
create policy "own folder select"
on storage.objects for select to authenticated
using (
bucket_id = 'user-uploads'
and (storage.foldername(name))[1] = (select auth.uid())::text
);
-- Only if you overwrite files with upsert: true
create policy "own folder update"
on storage.objects for update to authenticated
using (
bucket_id = 'user-uploads'
and (storage.foldername(name))[1] = (select auth.uid())::text
)
with check (
bucket_id = 'user-uploads'
and (storage.foldername(name))[1] = (select auth.uid())::text
);
-- Only if users can delete their own files
create policy "own folder delete"
on storage.objects for delete to authenticated
using (
bucket_id = 'user-uploads'
and (storage.foldername(name))[1] = (select auth.uid())::text
);
And upload to a matching path from the signed-in session:
const { data: { user } } = await supabase.auth.getUser()
const path = `${user.id}/${file.name}`
const { error } = await supabase.storage
.from('user-uploads')
.upload(path, file) // upsert defaults to false: INSERT policy only
Two details that trip people up: auth.uid() is a uuid and folder names are text, so cast it with ::text. And check the bucket in every policy. A policy that only checks the bucket, with no folder rule, lets any signed-in user add files to the whole bucket, and with upsert, overwrite other users' files.
Do I need upsert: true?
Usually not. Supabase's own advice: if you aren't deliberately overwriting files, leave upsert at its default of false and the INSERT policy is all you need. If you do overwrite (for example a profile photo always saved as avatar.png), keep upsert: true and add the SELECT and UPDATE policies above, scoped the same way as the INSERT one.
Will making the bucket public fix the upload?
No. Public changes who can download files, not who can upload them. Supabase says a public bucket bypasses access control for retrieving and serving files, while uploads, deletes, moves and copies still go through policies. Making a bucket public to "fix" uploads just exposes every file in it. Read are Supabase storage buckets public, and do public buckets skip RLS before you flip that switch.
Why not just use with check (true) or the service role key?
with check (true)with no role lets anyone holding your public key upload anything into your storage, including logged-out visitors. Evento authenticatedwithtruelets every account write into every folder.- The service role key bypasses all RLS. It belongs only on a server you control. If it ends up in browser code, anyone can read, replace or delete every file and every table. See is the Supabase anon key safe to expose? anon vs service_role.
How do I fix it in Lovable or Bolt?
Paste a request like this into the chat:
File uploads to the Supabase Storage bucket "user-uploads" fail with 403
"new row violates row-level security policy". Do not disable RLS, do not use
with check (true), do not make the bucket public and do not use the service
role key in the frontend. Upload each file to the path {user id}/{file name}
using the signed-in session. Add storage.objects policies for authenticated
users, scoped to bucket_id = 'user-uploads' and
(storage.foldername(name))[1] = (select auth.uid())::text: insert, select,
and update/delete only if the app overwrites or deletes files. If the code
uses upsert: true but never overwrites, set upsert to false. Show me the SQL
before running it.
Then test it: sign in as one user and upload a file, sign in as a second user and confirm they can't see, replace or delete the first user's file, and try an upload while logged out. It should fail.
Is this the same as permission denied for table?
No. new row violates row-level security policy means RLS refused the row. permission denied for table (42501) means the role has no grant on the table at all. For new tables in the public schema, read why a new Supabase table says permission denied for table. The same insert error on your own tables usually means a missing INSERT policy there; see how to check and fix open Supabase RLS in a Lovable app.
Related guides
- Are Supabase storage buckets public? Do public buckets skip RLS?
- Is the Supabase anon key safe to expose? anon vs service_role
- Why a new Supabase table says permission denied for table (42501)
- How to fix infinite recursion detected in policy (42P17)
- How to check and fix open Supabase RLS in a Lovable app
Want a weekly look from the outside? Run the free check on your live app.
FAQ
What does new row violates row-level security policy mean on a Supabase Storage upload?
Supabase Storage saves a row for every file in the storage.objects table, and that table has row level security on. The error means no policy on storage.objects allowed that row for the user making the request, so Storage refused the upload with a 403.
Which policy does a Supabase upload need?
A plain upload of a new file needs only an INSERT policy on storage.objects that matches the bucket and the file path. If the upload sets upsert to true, Storage also needs a SELECT policy, and an UPDATE policy to overwrite a file that already exists.
My bucket is public. Why can't I upload to it?
Public only affects downloads. Supabase says a public bucket bypasses access control for retrieving and serving files, but uploads, deletes, moves and copies still need policies on storage.objects.
Can I fix it with with check (true) or the service role key?
Not safely. with check (true) lets anyone the policy covers upload anything anywhere in the bucket, and the service role key bypasses RLS completely and must never be in browser code. Add a policy scoped to the bucket and the user's own folder instead.
Does the MondayMedic free check look at storage upload policies?
No. The free check reads your live app from the outside and flags Supabase tables the public key can read and secret keys in the browser. It does not read your storage policies. Use the SQL in this guide to see which storage.objects policies you have.
Sources
- Supabase docs: Storage Access Control (INSERT for uploads; SELECT and UPDATE for upsert; policy examples)
- Supabase troubleshooting: 403 Forbidden new row violates row-level security policy on upload
- Supabase docs: Storage helper functions (storage.foldername)
- Supabase docs: Storage ownership (owner_id)
- Supabase docs: Storage buckets (public vs private)