Supabase storage upload fails: 403 "new row violates row-level security policy"
Users click upload and nothing happens. The console shows StorageApiError: new row violates row-level security policy with status 403. Every Supabase bucket has row-level security on storage.objects, and no policy is letting this upload through. Making the bucket public doesn't help: that only makes files readable by URL. Here's the safe fix.
Stuck on this? Get it fixed for €49.
Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.
Get it fixed for €491. Confirm the user is actually signed in
Policies for authenticated users never match a signed-out request. Log (await supabase.auth.getSession()).data.session just before the upload. If it's null, fix the login flow first; the upload is running as the anonymous role.
2. Add an INSERT policy for the bucket
In Supabase, open SQL Editor and add a policy scoped to the user's own folder (replace avatars with your bucket name):
create policy "Users upload to own folder"
on storage.objects for insert to authenticated
with check (
bucket_id = 'avatars'
and (storage.foldername(name))[1] = (select auth.uid())::text
);
3. Make the upload path match the policy
That policy needs the path to start with the user's ID. Uploading to avatar.png at the bucket root fails. Use:
const { data: { user } } = await supabase.auth.getUser()
await supabase.storage.from('avatars')
.upload(`${user.id}/avatar.png`, file)
AI tools often use a profile ID or a random ID as the folder. If that's not the auth user's ID, the policy won't match.
4. Using upsert: true? Add SELECT and UPDATE too
Overwriting a file needs Supabase to read the existing row back. Without a matching SELECT policy you get the same 403 even when INSERT is fine. Either drop upsert: true or add:
create policy "Users read 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 own files" on storage.objects
for update to authenticated
using (bucket_id = 'avatars'
and (storage.foldername(name))[1] = (select auth.uid())::text);
5. Don't take the "quick fix"
If you ask the AI to fix it, it may disable RLS or add a policy with using (true). That stops the error and lets anyone with your public key upload, overwrite or delete every file in the bucket. Scope every policy to bucket_id and the user's folder.
Quick checklist
- A session exists at the moment of upload
- INSERT policy on
storage.objectsfor the right bucket and role - Upload path starts with
auth.uid() - SELECT and UPDATE policies if you use
upsert: true - No
using (true)or disabled RLS on storage
Stuck on this? Get it fixed for €49.
Fixed in 48 hours or you don't pay. Launch deal for the first 5 customers (normally €79). You get the tested fix as a pull request, so nothing changes until you merge it.
Get it fixed for €49Still stuck?
Mendlark fixes this kind of problem for a fixed €49 (launch price, normally €79). We agree the problem first, test the fix and send it as a pull request, so nothing changes in your app until you merge it. If we can't fix it, you don't pay. Get the €49 fix, or start with a free scan.
Not sure what else is wrong? Paste your app link into the free instant check and get a plain-English list of problems in seconds.