caelo

Caelo › Guides › Public Supabase bucket

Supabase storage bucket public by mistake? How to lock it down

By Arthi Arumugam, Irth Labs · Published · Updated

Short answerA public Supabase bucket lets anyone with a file's URL download it with no access check. Uploads, deletes and moves still go through row level security policies on 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

  1. List your buckets and which are public: select id, public from storage.buckets; in the SQL editor, or the Storage page of the dashboard.
  2. For each public bucket, decide whether every file in it is meant for anyone on the internet. If not, it should be private.
  3. Make it private in the dashboard, or from server code with the secret key: await admin.storage.updateBucket("invoices", { public: false }).
  4. Replace getPublicUrl calls for that bucket with createSignedUrl or download. Public URLs stop working once the bucket is private, which is the point.
  5. 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.
  6. 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)

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.

Book the App Health Check See repair services

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