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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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 withcreateSignedUrllinks 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:
- 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.
- 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 aspublic_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
SELECTorALLpolicy for{public},{anon}or{authenticated}whoseusing_expris only(bucket_id = 'something')ortrue: anyone in that role can list the bucket. - An
INSERT,UPDATEorDELETEpolicy whose check is only the bucket id, ortrue: 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.
Want us to look at your app?
VibeCPR Rescue Reports are launching soon: we scan your repo and live app, and a human verifies every critical finding. Join the waitlist for early access and founder pricing. You'll also get Patch Notes, our weekly fixes newsletter.
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
- Supabase Advisors: 0025 Public bucket allows listing
- Supabase docs: Storage buckets (public vs private access model)
- Supabase docs: Storage access control
Related fixes
- AI agent pushed API keys to GitHub? git commit --no-verify skipped your pre-commit hook
- Fix a surprise AI API bill: rate limits and spend caps
- Your app is public to anyone with the link: a share link is not a login
- Triage Bolt's "RLS Policy Always True" warning: when it's fine and how to fix it
- Fix secrets leaked via Claude Code .claude/settings.local.json
- Fix "Your Cloud Firestore database has insecure rules" (Firebase email)
- Login lockout keyed only on email? Rate-limit by IP and account without locking users out
- Fix Lovable "Invalid API key" after rotating Supabase keys (anon, publishable, secret)
- Lovable won't publish because of security findings? What each finding means and how to fix it
- "Sign in with Google" lets anyone in: restrict who can use your app (allowlist, domain check, RLS)
- Fix Stripe sk_live keys left in MCP or agent config
- Fix Stripe webhook "No signatures found matching the expected signature for payload"
- Fix Supabase auth redirecting to localhost after deploy
- Fix Supabase Edge Function "blocked by CORS policy" (preflight)
- Fix Supabase "infinite recursion detected in policy for relation" (42P17) in RLS
- Form says success but no row in Supabase (or Stripe webhook returns 200 but writes nothing)
- Fix "new row violates row-level security policy for table" (Supabase)
- Supabase only returns 1,000 rows? Fix the silent max rows limit in Lovable and Bolt apps
- Fix Supabase "permission denied for table" (42501) on new tables after Oct 30, 2026
- Supabase Realtime leaking rows or not receiving changes: fix RLS and the publication
- Supabase RLS not working on the server? Your API uses the service_role or secret key
- Fix Supabase RLS policy USING (true) that makes a table publicly readable
- Your app's rules only live in the frontend: move them into Supabase
- Fix a Supabase SECURITY DEFINER function anyone can call through /rest/v1/rpc
- Fix Supabase .single() "JSON object requested, multiple (or no) rows returned" (PGRST116)
- Stop Supabase users from upgrading their own plan or making themselves admin
- Fix a Supabase view that bypasses RLS: security_invoker and revoking anon write grants
- Fix "404: NOT_FOUND" on refresh in a React/Vite app on Vercel (vercel.json rewrite)
- Fix "Module not found: Can't resolve" on Vercel (works locally)
- Is my Vite dev server exposed? Check --host / server.host and patch the RCE (GHSA-p4f5-76q4-ffq7)