Supabase Storage Upload Fails RLS But service_role Works (2026)

Your upload fails. The error says new row violates row-level security policy. You read the policy, you test it in the SQL editor, it returns true. You swap the anon key for service_role to check you are not going mad, and the upload works instantly.

That sequence has a specific ending, and we see it in scans constantly: the service key stays in the code, ships to production, and now the whole project is readable by anyone who opens the JavaScript bundle. This page is about not getting there.

(Updated 2026-11-02: Supabase has corrected its troubleshooting page. It now says the SELECT-policy fix applies only to upsert: true, which is what this post argued. The Storage source still behaves as described below.)

TL;DR

Until recently, Supabase's troubleshooting page for this error said the Storage API runs INSERT ... RETURNING * and told everyone to add a SELECT policy. That is true for upsert: true and not for a normal upload: the Storage source only attaches RETURNING * to the upsert path, and Supabase's own access control guide says INSERT alone is what an upload needs. As of 2026-11-02 the troubleshooting page agrees and scopes the fix to upserts. If you are not upserting, adding the SELECT policy anyway widens read access on storage.objects and usually leaves the real bug in place.

First, the status code is probably not 403

Almost every writeup of this error, including the title of Supabase's own troubleshooting entry, calls it a 403.

The status on the wire is usually 400. What you get back looks like this:

What the Storage API actually returns
{
  "statusCode": "403",
  "error": "Unauthorized",
  "message": "new row violates row-level security policy"
}

The 403 is a string inside the body. The HTTP response is a 400. If you are filtering your browser's network tab by status, filter on the message text instead, or you will scroll past the failing request looking for a red 403 that never appears.

Supabase's Storage service also normalises the Postgres error before returning it. Postgres raises 42501 with a message ending ... for table "objects"; Storage maps that to the shorter string above. So the wording you see from the API and the wording in your database logs are not identical, and searching for one will not find the other.

The fix in the docs, and where it comes from

When we first checked it on 2026-08-24, Supabase's troubleshooting entry gave this cause:

The Supabase Storage API executes an INSERT operation followed by a RETURNING * clause to provide object details back to the client.

And this consequence: if a SELECT policy is missing, "the database is unable to return the row metadata," so the whole transaction fails. The prescribed fix was a SELECT policy on storage.objects mirroring your INSERT conditions, with no mention of upsert.

It was a plausible story. It is also the exact mechanism that bites people using supabase-js to insert into a normal table, where the client does append a select to return the full record. Table inserts go through PostgREST. Storage does not.

What the Storage source actually does

The Storage service builds two different statements, and only one of them returns anything.

supabase/storage, src/storage/database/pg.ts
-- createObject: a normal upload
INSERT INTO storage.objects (${insert.columns})
VALUES (${insert.placeholders})
-- no RETURNING clause

-- upsertObject: upload with upsert enabled
INSERT INTO storage.objects (${insert.columns})
VALUES (${insert.placeholders})
ON CONFLICT (name, bucket_id) DO UPDATE SET ${updateClause}
RETURNING *

A plain upload never asks the database to hand the row back, so there is nothing for a missing SELECT policy to block. This is not a recent change that the docs failed to catch up with, either: the older knex implementation had the same split, with .returning('*') only on the upsert method.

Supabase's access control guide says it plainly, and contradicted the old troubleshooting page:

the only RLS policy required for uploading objects is to grant the INSERT permission to the storage.objects table. To allow overwriting files using the upsert functionality you will need to additionally grant SELECT and UPDATE permissions.

As of 2026-11-02 the troubleshooting entry has been rewritten and now lives in Supabase's knowledge base. It opens with "Important: this only happens when upsert: true" and says that with upsert: false "a correctly-scoped INSERT policy is all that's required." The unfilled example_schema.example_table placeholder that the old version carried is gone. One gap remains: for upserts it tells you to add a SELECT policy only, while the access control guide says you need SELECT and UPDATE. Follow the access control guide.

So: if you pass { upsert: true }, the docs are right and you need SELECT and UPDATE as well. If you do not, adding a broad SELECT policy grants every matching user read access to object metadata they previously could not see, and your upload still fails.

What to check instead

1

Confirm whether you are upserting. Look for { upsert: true } in the .upload() call. If it is there, add SELECT and UPDATE policies matching your INSERT conditions and you are done.

2

Stop testing the policy in the SQL editor. This is the single most misleading step in the whole debugging loop. The editor runs without request.jwt.claims set, so any auth.uid() or JWT-claim expression in your policy evaluates in a context the real request never has. A policy that returns true there has told you nothing.

3

Check the path, not just the user. Storage policies almost always match on the object name, and storage.foldername(name) or split_part(name, '/', 1) against a user ID is where these break. Log the exact name your client sends and compare it character for character with what the policy expects. A leading slash, or userId where the policy wants auth.uid()::text, fails silently as a policy mismatch.

4

Reproduce with curl and a real user JWT, not the anon key alone. That is the only way to see the policy evaluated with the same claims your app sends.

Reproduce the failure with the real auth context
# Grab a real session token from your app (browser devtools, Application, Local Storage)
TOKEN="eyJ..."
PROJECT="your-project-ref"

curl -i -X POST \
  "https://$PROJECT.supabase.co/storage/v1/object/your-bucket/$(uuidgen).png" \
  -H "Authorization: Bearer $TOKEN" \
  -H "apikey: $YOUR_ANON_KEY" \
  -H "Content-Type: image/png" \
  --data-binary @test.png
5

Check for triggers on the storage schema. A failing trigger can surface as a policy-shaped error that has nothing to do with your policies. One reported case of this exact message turned out to be a broken trigger, with the user already on service_role and RLS not involved at all. A Storage server change merged on 2026-10-28 (supabase/storage #1600) makes a trigger that blocks the write fail with its own message, Object write was rejected by a database trigger, so on a Storage version with that change you can tell the two apart from the message alone.

Why this one is worth writing about

Three GitHub discussions carry this shape, and as of 2026-11-02 none has an accepted answer: #46022 (2026-05-16), #48349 (2026-07-27), and #37611 (2025-08-01).

Worth being precise about what those threads do and do not show. They are not unanswered: #46022 drew two substantive diagnostic replies, and the best reply in #48349 is the request.jwt.claims point above. Nobody in any of them recommends using service_role as the fix. One responder raises it specifically to draw the distinction, that service_role bypasses RLS and anon does not.

What the threads do show is the temptation. The title of #48349 is a developer reporting that the upload "works with service_role" and that the anon key does not. That is a person with a deadline, an error message whose official explanation does not apply to them, and one key sitting right there that makes the problem go away.

What reaching for the service key actually costs

service_role (a secret key in Supabase's newer key format) uses Postgres's BYPASSRLS attribute. That is a role attribute, not a per-table setting, so it does not just open the bucket. Supabase documents it as having "full access to your project's data, bypassing Row Level Security," and service keys as "entirely bypass[ing] RLS policies, granting you unrestricted access to all Storage APIs."

Put that key in a React or Vue app and it is compiled into a JavaScript file your visitors download. Every table, every row, read and write, for anyone who opens devtools. This is the single most damaging finding we produce in scans of AI-built apps, and it does not usually arrive through carelessness. It arrives through exactly the sequence at the top of this page.

The anon key is genuinely safe in a browser. Supabase describes the publishable key as "safe to expose online: web page, mobile or desktop app, GitHub actions, CLIs, source code," because RLS is what guards it. The secret key has no such property, and no policy you write applies to it.

If you already shipped one, treat it as burned: rotate it in the dashboard first, then fetch your deployed bundles and grep for JWT-shaped strings to confirm nothing else went out with it. Rotation before investigation, every time.

Sources

ClaimSourceChecked
Troubleshooting page blamed INSERT ... RETURNING * and prescribed a SELECT policy (2026-08-24); now scoped to upsert: true (2026-11-02)Supabase troubleshooting a943842026-11-02
createObject issues no RETURNING; only upsertObject doessupabase/storage src/storage/database/pg.ts2026-11-02
INSERT alone is required to upload; SELECT and UPDATE only for upsertSupabase Storage access control2026-11-02
supabase-js table inserts do append a select, which is where the mechanism is realsupabase-js insert reference2026-11-02
service_role uses BYPASSRLS; publishable/anon key is safe to exposeSupabase API keys2026-11-02
Trigger-blocked writes now return their own errorsupabase/storage #16002026-11-02
Unresolved reports of this error#46022, #48349, #376112026-11-02

Why does my Supabase Storage upload fail with the anon key but work with service_role?

Because service_role carries Postgres's BYPASSRLS attribute, so it skips every policy you wrote rather than satisfying them. It working is not evidence your policy is correct. It is evidence your policy is being evaluated at all, and failing, which narrows the bug to the policy or to the auth context the request arrives with.

Is the Supabase Storage RLS upload error a 403 or a 400?

The HTTP status on the wire is usually 400. The JSON body contains a statusCode field with the string 403 in it, which is where the confusion comes from. If you are filtering your network tab for 403 you will miss the request entirely, so filter on the message text instead.

Do I need a SELECT policy on storage.objects to upload a file?

Not for a plain upload. Supabase's access control guide states that the only RLS policy required for uploading is INSERT on storage.objects, and that SELECT and UPDATE are needed additionally only for upsert. Their troubleshooting page used to prescribe a SELECT policy for the error generally. As of 2026-11-02 it has been corrected to say the error only happens with upsert: true, which matches the access control guide and the Storage source code.

Why does my policy pass in the SQL editor but fail from the app?

The SQL editor runs without request.jwt.claims set, so anything in your policy that reads auth.uid() or a JWT claim evaluates differently there than it does on a real request. A policy that returns true in the editor has told you almost nothing about what happens when the Storage API runs it.

What happens if I ship the service_role key to fix this?

You expose the entire project, not just the bucket. BYPASSRLS is a Postgres role attribute rather than a per-table setting, and Supabase documents service keys as entirely bypassing RLS policies with unrestricted access to all Storage APIs. Anyone who opens your JavaScript bundle can then read and write every table you have.

Is a service key in your bundle right now?

We fetch your deployed JavaScript, decode every JWT in it, and tell you which ones bypass your policies.

How-To Guides

Supabase Storage Upload Fails RLS But service_role Works (2026)