Supabase Storage "Object not found": the RLS cause
#supabase#storage#rls#signed-urls#security
{"statusCode":"404","error":"not_found","message":"Object not found"} from Supabase Storage, for a file you can see in the dashboard, almost always means RLS hid it: in a private bucket, download(), createSignedUrl() and list() look the file up as the signed-in user, and without a matching select policy on storage.objects the row isn't there. Fix it with a select policy scoped to the file's owner. A policy that only checks bucket_id also makes the error go away, and lets every signed-in user read every file in the bucket.
The error doesn't say "permission denied", which is why this one costs people an afternoon. The file exists, the upload succeeded, and the path is right. Storage isn't wrong either: the query it ran as you returned no rows.
Why does Supabase Storage say "Object not found" when the file exists?
Because in a private bucket the lookup runs under your RLS policies, and a row RLS filters out looks exactly like a row that doesn't exist.
Here's the path through the Storage server. The download route (src/http/routes/object/getObject.ts) first finds the bucket as the superuser. Then it branches on the bucket's public flag:
if (bucket.public) {
// request is authenticated but we still use the superUser as we don't need to check RLS
obj = await request.storage.asSuperUser().from(bucketName).findObject(objectName, ...)
} else {
// request is authenticated use RLS
obj = await request.storage.from(bucketName).findObject(objectName, ...)
}
For a private bucket, findObject (src/storage/database/pg.ts) runs a plain SELECT ... FROM storage.objects WHERE name = $1 AND bucket_id = $2 on the caller's connection, so Postgres applies your policies for the authenticated (or anon) role. If no select policy matches that row, the result is empty, and findObject throws NoSuchKey. Its definition in src/internal/errors/codes.ts is error: 'not_found', httpStatusCode: 404, message: 'Object not found'.
createSignedUrl() takes the same road: signObjectUrl in src/storage/object.ts calls findObject before it signs anything, so it can't sign a URL for a file you aren't allowed to select. list() has no error to throw. It just returns [], the same silent filter you get from a select that returns an empty array on any other table.
As with most Storage errors, the response arrives with HTTP status 400 and the real status as a string in the body. Read the body, not the network tab's status column.
The fix that makes it worse
When a file "isn't found", the quickest thing that works is a broader policy:
- Warningsupabase/migrations/20261201090000_documents_read_policy.sql:3
RLS policy without user scoping
Scope the policy to the requesting user/role, e.g. USING (auth.uid() = user_id). If the data is intentionally public, make that explicit and document it.
It does work. It also means any account on your app (including one a stranger made a minute ago through your public signup) can call createSignedUrl() or download() for any path in documents, and list() every folder in it. If the bucket holds invoices, ID scans or contract PDFs, that's every customer's file behind one free signup.
GuardLayer flags it as supabase/policy-no-user-scope, because the predicate never mentions the user: nothing in bucket_id = 'documents' ties a row to auth.uid(). The same goes for to public using (true), reported as supabase/policy-using-true, which is wider still because it covers the anon role too. Switching the bucket to public is the third version of this fix, and it skips RLS altogether, as covered in public vs private buckets.
How do I fix "Object not found" in a private bucket?
Add a select policy that matches the file's owner. There are two common ways to express ownership.
By folder. Upload each user's files under their user id, then check the first path segment:
create policy "read own documents"
on storage.objects for select to authenticated
using (
bucket_id = 'documents'
and (storage.foldername(name))[1] = (select auth.uid())::text
);
That pairs with an upload path like ${user.id}/contract.pdf. It's also the shape you need for the insert side, which is where the upload RLS error comes from.
By owner column. Storage records who uploaded each object in storage.objects.owner_id (text), taken from the uploader's JWT:
create policy "read own documents"
on storage.objects for select to authenticated
using (
bucket_id = 'documents'
and owner_id = (select auth.uid())::text
);
Use the folder form if anyone other than the uploader writes into a user's space, such as an admin or a server job using the service role. owner_id is whoever did the upload, and a service-role upload has no user id to record, so the owner check never matches those files.
For files shared within a team, scope through a membership table rather than widening to the bucket. The pattern is the same as multi-tenant RLS on any other table: check that the folder's team id appears in the caller's memberships.
When it isn't RLS
If the policy is right and the error stays, check the path. These cause the same error with no policy involved:
| Mistake | Example | Fix |
|---|---|---|
| Bucket name repeated in the path | from('documents').download('documents/a.pdf') | The path is relative to the bucket: 'a.pdf' or '<uid>/a.pdf' |
| Leading slash | '/<uid>/a.pdf' | Drop the leading / |
| Case or extension differs | Contract.PDF vs contract.pdf | Names are compared byte for byte; copy the path from the upload response's data.path |
| Wrong project or environment | Works locally, fails in production | Check NEXT_PUBLIC_SUPABASE_URL and that the file was uploaded there |
| Public bucket | download() and public URLs look the file up as the superuser | Here "Object not found" from a download really means the file isn't there at that path |
A related 400 is Invalid key: <name>. Storage checks every object name on upload, download and copy, and allows only ASCII letters, digits, spaces and _ / ! . * ' ( ) & $ = @ ; : + , ? - (isValidKey in src/storage/limits.ts). A name with å, é, #, % or an emoji fails before any lookup. Slugify file names before upload and keep the original name in a database column if you need to show it.
Store data.path from the upload response in your table and use it verbatim later. Rebuilding paths from pieces is where most of these come from.
How to tell RLS from a missing file
Run the lookup in the SQL Editor once as the superuser and once as the user. Get a real user id from auth.users first.
-- 1. Does the object exist at all?
select id, name, owner_id from storage.objects
where bucket_id = 'documents' and name = '<uid>/contract.pdf';
-- 2. Can that user see it?
begin;
select set_config('request.jwt.claims',
'{"sub":"<uid>","role":"authenticated"}', true);
set local role authenticated;
select id, name from storage.objects
where bucket_id = 'documents' and name = '<uid>/contract.pdf';
rollback;
Row in the first query, nothing in the second: it's RLS, and the fix is the policy above. Nothing in either: the path is wrong. To see what you have today:
select policyname, cmd, roles, qual
from pg_policies
where schemaname = 'storage' and tablename = 'objects';
Any select row whose qual is just (bucket_id = 'documents'::text), or true, is readable by every user that role covers.
FAQ
Why does the dashboard show the file but my app gets "Object not found"?
The dashboard reads Storage with elevated rights, so RLS doesn't apply to it. Your app reads as the signed-in user, and in a private bucket that read only returns rows a select policy allows.
Do I need a SELECT policy to create a signed URL?
Yes. createSignedUrl() looks the object up as the caller before signing it, so the user needs a select policy that matches the path. Once issued, the signed URL itself works without a session until it expires, which is why signed URL lifetimes should be short.
Why does list() return an empty array instead of an error?
It's the same RLS filter applied to many rows. A list query with no visible rows is a successful query with zero results. Fix the select policy and the files appear.
Is "Object not found" the same as "Bucket not found"? No. "Object not found" comes from the object lookup and, in a private bucket, usually means RLS. Bucket not found usually means a public URL pointed at a private bucket, or the bucket isn't in that project.
Can I just call download() with the service role on the server? You can, and the service role skips RLS, so it will find the file. Then your server code is the only access check, and it has to verify that the signed-in user owns that path before returning anything. An owner-scoped policy does that check in the database for every caller.
See which of your Supabase tables anyone can read, free
Connect your Supabase project read-only. GuardLayer checks RLS, policies, grants and functions as they are right now, and gives you the SQL to fix each problem. It never reads your rows and can't change anything.
Check my Supabase projectPrefer to check code instead? Scan your repo, no signup.