Supabase storage bucket public by mistake? How to lock it down
storage.objects. If the bucket holds private files, make it private, serve files with signed URLs or authenticated downloads, and add policies that limit each user to their own folder.What does public actually mean?
Supabase's docs say a public bucket "bypasses access controls for both retrieving and serving files within the bucket" and that "anyone with the asset URL can access the file." For uploading, deleting, moving and copying, "access control is still enforced", and by default Storage does not allow any uploads to buckets without RLS policies.
So public is right for avatars, product photos and blog images, and wrong for invoices, ID documents, contracts or anything a user uploads expecting privacy. File names that look random are not a protection: URLs end up in logs, emails and browser history.
The vulnerable pattern and the fix
Vulnerable: a private kind of file in a public bucket, with an open upload policy
insert into storage.buckets (id, name, public) values ('invoices', 'invoices', true);
create policy "uploads" on storage.objects
for insert with check (true); -- anyone, signed in or not, can upload anywhere
Fixed: each user reads and writes only their own folder
create policy "Users upload to their own folder"
on storage.objects for insert to authenticated
with check (
bucket_id = 'invoices'
and (storage.foldername(name))[1] = (select auth.jwt()->>'sub')
);
create policy "Users read their own folder"
on storage.objects for select to authenticated
using (
bucket_id = 'invoices'
and (storage.foldername(name))[1] = (select auth.jwt()->>'sub')
);
Upload into the user's folder and share with a short-lived signed URL
const { data: { user } } = await supabase.auth.getUser();
await supabase.storage.from("invoices").upload(user.id + "/march.pdf", file);
const { data } = await supabase.storage
.from("invoices")
.createSignedUrl(user.id + "/march.pdf", 60); // valid for 60 seconds
The upload policy is the one from Supabase's access control docs. storage.foldername(name) splits the object path into folders, and the first folder must equal the signed-in user's ID.
Fix it, step by step
- List your buckets and which are public:
select id, public from storage.buckets;in the SQL editor, or the Storage page of the dashboard. - For each public bucket, decide whether every file in it is meant for anyone on the internet. If not, it should be private.
- Make it private in the dashboard, or from server code with the secret key:
await admin.storage.updateBucket("invoices", { public: false }). - Replace
getPublicUrlcalls for that bucket withcreateSignedUrlordownload. Public URLs stop working once the bucket is private, which is the point. - Store each user's files under a folder named after their user ID and add policies like the ones above. Add update and delete policies only if users need them.
- Assume files were readable while the bucket was public. If they were sensitive, decide whether the people affected need to be told.
Check it automatically
Caelo reads the SQL migrations in your supabase folder and flags policies whose condition is literally true, including policies on storage.objects (supabase.permissive-policy and supabase.public-read-policy). It does not check whether a bucket is set to public, either in an insert into storage.buckets line or in the dashboard, so look at the bucket list yourself.
Caelo output for the open upload policy above
- RLS policy lets the role insert any row [needs review]
supabase/migrations/001.sql:5 (supabase.permissive-policy)
value: storage.objects: for insert to public, condition is (true)
- Install Caelo: npx caelo . or the MCP server
- How Caelo compares with gitleaks, TruffleHog, Semgrep and others
1. Run the free local check
npx caelo .
Caelo is a free, open source (MIT) command line tool and MCP server from Irth Labs that checks the files of an AI-built app for exposed API keys, Supabase and Firebase misconfigurations and .env files with real values. It runs on your machine, uploads nothing and uses no AI model. Each finding comes with a plain-English fix.
2. Act on a finding
Follow the fix in your report and run Caelo again. If Git could commit an untracked file containing secrets, preview a US$19 quick fix for that file.
For findings that need an engineer, Irth Labs offers a US$490 App Health Check. You receive a written report within 48 hours and a fixed repair quote. The fee counts toward the repair if you proceed.
Questions
Can RLS policies protect downloads from a public bucket?
No. Supabase says a public bucket bypasses access controls for retrieving and serving files. Policies on storage.objects still control uploads, deletes and moves, but not public downloads.
Why can't I upload to my public bucket?
Because public only affects downloads. Uploads need an insert policy on storage.objects, and by default there is none.
How long should a signed URL last?
As short as your use allows. The expiry is in seconds, so 60 is one minute. Create a fresh one each time a user opens the file rather than storing long-lived links.
Sources
- Supabase docs: Storage buckets fundamentals (public and private buckets).
- Supabase docs: Storage access control.
- Supabase reference: createSignedUrl.
- Supabase reference: updateBucket.
- Supabase troubleshooting: Why can't I upload, list or delete in my public bucket.
- Caelo source: every rule in lib/rules.js.