VibeCPR

← All fixes

Supabase · Storage · RLS

Fix a Supabase public Storage bucket that lets anyone list or download your files

Updated · Applies to: Supabase, Lovable, Bolt, v0, Cursor, Replit, Claude Code

TL;DR fix: A public Supabase bucket skips access control for downloads: anyone with a file's URL can fetch it, no policy needed. If you also add a broad SELECT policy on storage.objects (like bucket_id = 'avatars' or true), clients can list every file in the bucket, which Security Advisor flags as public_bucket_allows_listing (lint 0025). Fix: drop that policy (public URLs keep working). If the bucket holds anything private, such as IDs, invoices, uploads or event photos, make it private with update storage.buckets set public = false, add per-user policies, and serve files with signed URLs.

Steps

  1. List your buckets and which are public. Run the bucket query below. Any bucket with public = true serves every file to anyone who has or guesses its URL, whatever your policies say.
  2. List the SELECT policies on storage.objects. Run the policy query below. A permissive SELECT or ALL policy for public, anon or authenticated whose condition is only bucket_id = 'x' or true lets clients list everything in that bucket.
  3. Drop listing policies on public buckets. Public buckets don't need a SELECT policy for their file URLs to work. Dropping the broad policy stops listing and keeps your images loading.
  4. Make buckets with private files private. If a bucket holds anything a stranger shouldn't see, set public = false. Private buckets apply RLS to downloads too.
  5. Add per-user policies and use signed URLs. Scope uploads and reads to a folder named after the user's id, and have the app call createSignedUrl for time-limited links instead of storing public URLs.
  6. Check uploads, updates and deletes. Public only covers downloads. Uploads, overwrites, moves and deletes still go through your policies, so make sure no INSERT, UPDATE or DELETE policy on storage.objects is just true or bucket-only for anon.

What’s actually exposed

Supabase Storage buckets come in two kinds, and they behave very differently:

  • Private (the default): every operation, downloads included, goes through RLS policies on storage.objects. Files are shared with a user’s token or with createSignedUrl links that expire.
  • Public: Supabase’s docs say a public bucket “effectively bypasses access controls for both retrieving and serving files”. Anyone with a file’s URL can download it. Uploads, deletes, moves and copies are still checked.

Two mistakes show up again and again in apps built with AI tools:

  1. Private files in a public bucket. The tool flips the bucket to public because a signed URL felt like extra work, and now ID scans, receipts or customer photos are one URL away from anyone.
  2. A listing policy on a public bucket. The tool adds create policy ... for select using (bucket_id = 'avatars') “so images load”. Public buckets don’t need it, and it lets any client list every file name. Security Advisor flags this as public_bucket_allows_listing.

Find risky buckets and policies

Run both in the SQL editor.

-- Which buckets are public?
select id, name, public, file_size_limit, allowed_mime_types
from storage.buckets
order by public desc, id;
-- Which policies on storage.objects could allow listing or open writes?
select policyname, cmd, roles, permissive, qual as using_expr, with_check
from pg_policies
where schemaname = 'storage' and tablename = 'objects'
order by cmd, policyname;

Read the second result like this:

  • A SELECT or ALL policy for {public}, {anon} or {authenticated} whose using_expr is only (bucket_id = 'something') or true: anyone in that role can list the bucket.
  • An INSERT, UPDATE or DELETE policy whose check is only the bucket id, or true: anyone in that role can upload, overwrite or delete files there.
  • Conditions that also check owner_id, auth.uid(), auth.jwt()->>'sub' or the user’s folder are what you want.

Fix 1: stop listing on a public bucket

If the bucket really is meant to be public (avatars, blog images), drop the broad policy. Supabase’s docs say public object URLs keep working without it.

drop policy if exists "Public bucket listing" on storage.objects;  -- use your policy name

If your app listed the bucket to build a gallery, store the file paths in your own table (with its own RLS) and read them from there.

Fix 2: make a bucket with private files private

update storage.buckets set public = false where id = 'documents';  -- your bucket id

Then give each user access only to their own folder. These follow Supabase’s documented examples, where each user uploads into a folder named after their id:

create policy "Users upload to their own folder"
on storage.objects for insert to authenticated
with check (
  bucket_id = 'documents'
  and (storage.foldername(name))[1] = (select auth.jwt()->>'sub')
);

create policy "Users read their own files"
on storage.objects for select to authenticated
using (
  bucket_id = 'documents'
  and (select auth.jwt()->>'sub') = owner_id
);

And in the app, swap stored public URLs for short-lived signed URLs:

const { data, error } = await supabase.storage
  .from('documents')
  .createSignedUrl(`${user.id}/receipt.pdf`, 60 * 10); // valid for 10 minutes

Making the bucket private breaks every public URL you already saved in the database, so update those reads in the same change. Links that were shared while the bucket was public stop working too, which is what you want.

Fix 3: lock down writes

Public buckets still enforce policies for uploads and deletes, so the danger there is a write policy that’s too broad. Replace anything like with check (bucket_id = 'avatars') for anon with a per-user folder check like the one above, scoped to authenticated.

Retest

From a logged-out browser or curl with only your anon key, try listing a bucket and downloading a file you shouldn’t be able to see. Listing should return nothing, private files should need a signed URL, and Security Advisor should no longer show public_bucket_allows_listing.

Storage is only one of the ways a Supabase app leaks data. The same audit mindset applies to tables with USING (true) policies, views that bypass RLS and SECURITY DEFINER functions anyone can call.

Prompt for Cursor, Lovable, Bolt or Claude Code

Audit Supabase Storage in my project. List every bucket with its public flag and every
policy on storage.objects with its command, roles and condition. Assume the anon key is
public and anyone can sign up. For each bucket tell me whether it holds anything private.
Then: drop broad SELECT policies on public buckets, make buckets holding private files
private, scope uploads and reads to a folder named after the user's id, and switch the app
from stored public URLs to createSignedUrl. Show me the SQL and code changes before running.

When to get help

Get help if a bucket held private files while public and you need to work out what was exposed, if your app stores public URLs in the database and needs moving to signed URLs, or if you want a full review before launch.

FAQ

What does a public bucket mean in Supabase Storage?

Supabase docs say a public bucket bypasses access controls for retrieving and serving files: anyone with the file URL can download it. Uploading, deleting, moving and copying are still checked against your RLS policies. Buckets are private by default.

What does the public_bucket_allows_listing warning mean?

Supabase Security Advisor lint 0025 fires when a public bucket also has a broad permissive SELECT or ALL policy on storage.objects for public, anon or authenticated, with a condition like bucket_id = 'avatars' or true. That combination lets API clients list every object in the bucket. Public URLs work without the policy, so the usual fix is to drop it.

Will dropping the SELECT policy break my images?

Not for a public bucket. Supabase's docs say public buckets do not need a SELECT policy for clients to fetch known object paths, and that object URLs keep working after you remove it. It does stop listing, so if your app lists the bucket (for a gallery, say), read the file paths from your own table instead.

Should my bucket be public or private?

Public suits files you would happily post online: avatars, blog images, product photos. Anything personal belongs in a private bucket: ID documents, invoices, receipts, private uploads, event or customer photos. Private buckets apply RLS to downloads, and the app shares files with createSignedUrl links that expire.

Is the file URL secret enough if the name is random?

No. A public URL works for anyone who has it, and links leak through browser history, shared screenshots, logs and referrer headers. If a broad SELECT policy also exists, the names are listable anyway. Use a private bucket and signed URLs for anything sensitive.

Sources

Related fixes