Deutsch
Fix libraryHighSupabase · Storage

Public storage bucket with private files: make it private and serve signed URLs

Files in a public Supabase bucket can be opened by anyone with the link, no policy asked. Find public buckets, make private ones private and switch to signed URLs.

By Tim GeithnerPublished 3 min read

ShipRely's Database & Supabase audit checks for this today.

Short answer

A public Supabase Storage bucket serves every file to anyone who has its URL, without checking any policy. That is right for avatars and blog images, and wrong for invoices, contracts or ID scans. A broad select policy can also let anyone list the files. Make the bucket private, give each user a folder protected by policies on storage.objects, and hand out short-lived signed URLs instead of public ones.

Ask an AI about this page:ChatGPTClaude

On this page

A public bucket in Supabase Storage serves its files to anyone who has the URL, and Supabase checks no policy for those downloads. That is fine for profile pictures and blog images. It is a leak when the bucket holds invoices, contracts, ID scans or anything else that belongs to one user. It is rated high: the files are exposed to anyone who obtains a link, and if a broad select policy is in place, the list of files is too.

Why it matters

Supabase’s docs are explicit: a public bucket bypasses access control when files are retrieved and served, and anyone with the asset URL can open the file. It is tempting to make a bucket public, because getPublicUrl() is the simplest way to show an uploaded file. A typical setup for an invoicing app:

VulnerableThe vulnerable setup
insert into storage.buckets (id, name, public)
values ('invoices', 'invoices', true);

create policy "Public read access"
  on storage.objects for select
  using (bucket_id = 'invoices');

create policy "Users can upload invoices"
  on storage.objects for insert
  to authenticated
  with check (bucket_id = 'invoices');

Three things go wrong. Every invoice can be opened by URL without signing in. The select policy has no to clause and no owner condition, so anyone with your public key can also list every file name in the bucket, which turns “you need the link” into “here are all the links”. And the upload policy lets any user put files anywhere in the bucket, including into another user’s folder.

We can’t run the Storage API itself in our SQL test setup, so the download behaviour above comes from Supabase’s documentation. The policy behaviour (who can list and upload) we tested on a Postgres with Supabase’s roles.

How to find it in your app

In the dashboard, open Storage and look for buckets marked public. In the SQL Editor, this lists every bucket, whether it is public, and how many files it holds:

Buckets, public or not
select b.id as bucket, b.public, count(o.id) as files
from storage.buckets b
left join storage.objects o on o.bucket_id = b.id
group by b.id, b.public
order by b.public desc, b.id;

For every public bucket, ask: may every file in it be seen by anyone on the internet? Then look at the policies on storage.objects:

Policies on stored files
select policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'storage' and tablename = 'objects'
order by policyname;

A select policy that only checks bucket_id lets everyone it applies to list that bucket. The Security Advisor flags this for public buckets as lint 0025 (public_bucket_allows_listing). In your code, search for getPublicUrl(: each call on a private kind of file is a place to change.

How to fix it

Make the bucket private and give each user a folder named after their user ID, protected by policies:

SafeFix: private bucket, one folder per user
update storage.buckets set public = false where id = 'invoices';

drop policy "Public read access" on storage.objects;
drop policy "Users can upload invoices" on storage.objects;

create policy "Users read their own invoices"
  on storage.objects for select
  to authenticated
  using (
    bucket_id = 'invoices'
    and (storage.foldername(name))[1] = (select auth.uid()::text)
  );

create policy "Users upload into their own folder"
  on storage.objects for insert
  to authenticated
  with check (
    bucket_id = 'invoices'
    and (storage.foldername(name))[1] = (select auth.uid()::text)
  );

You can also switch the bucket to private in the dashboard under the bucket’s settings; the update does the same in a migration. Add update and delete policies with the same condition if users may replace or remove their files. Then change the frontend: upload each file into a folder named after the user’s ID, and show files through a signed URL instead of a public one:

Safesrc/lib/invoices.ts (sketch)
const { data, error } = await supabase.storage
  .from("invoices")
  .createSignedUrl(`${user.id}/${fileName}`, 60);

Files that were uploaded outside a user folder will no longer be readable by users; move them into the right folder with a server script. If the bucket was public for a while, assume its files may have been copied and treat it like any other data exposure. The Supabase Storage security guide covers shared folders and team buckets.

Make the invoices bucket private

The Supabase Storage bucket invoices (replace with yours) is public and holds private files. Add a new Supabase migration that sets the bucket to private, drops the existing storage.objects policies for this bucket, and creates select and insert policies for the authenticated role only that allow access when bucket_id = ‘invoices’ and (storage.foldername(name))[1] = (select auth.uid()::text). Add update and delete policies with the same condition if the app lets users replace or delete files.

Then change the frontend: upload files to the path userId/fileName, and replace every getPublicUrl call for this bucket with createSignedUrl with a short expiry. Do not make any other bucket public and do not use the service role key in the browser.

Check that the fix works

Act as a second user and list the bucket:

Check as another user
begin;
set local role authenticated;
set local request.jwt.claims = '{"sub": "22222222-2222-2222-2222-222222222222", "role": "authenticated"}';
select name from storage.objects where bucket_id = 'invoices';
rollback;

With a real user ID, only files in that user’s own folder may appear. Run the bucket query again: invoices must show public = false. Finally, test the real thing in a private browser window: open a link to one of the files that worked before. It must no longer load, while a signed URL created in your app opens the file and stops working after it expires. For tables, the matching check is in the table without RLS fix.

Frequently asked questions

Are file URLs in a public bucket secret if the file names are random?

No. The URL is the only thing protecting the file, and URLs end up in browser history, logs, shared messages and API responses. If a file is private, the bucket must be private.

Do public buckets need policies at all?

For downloads by public URL, no: Supabase skips access control there. Uploads, deletes, moves and copies are still checked, so you need policies for those. A broad select policy on a public bucket only adds the ability to list files.

What is a signed URL?

A link to one file in a private bucket that works until it expires. Your app creates it for a user who is allowed to see the file, for example with a lifetime of 60 seconds.

Will my old public links stop working after I make the bucket private?

Yes, and that is the point. Any page that showed files through getPublicUrl has to switch to signed URLs or authenticated downloads.

Sources

  1. 1.Storage buckets: fundamentals — Supabase Docs
  2. 2.Storage access control — Supabase Docs
  3. 3.Performance and Security Advisors — Supabase Docs
  4. 4.CWE-552: Files or Directories Accessible to External Parties — MITRE
  5. 5.A01 Broken Access Control — OWASP Top 10

Find this in your own app

ShipRely reads your repository (read-only), proves each finding with file and line, and gives you a fix prompt to paste into your AI builder.

Run a demo audit
  • Read-only access to your repository
  • Every finding with file and line
  • Fix prompts for Lovable, Cursor, Claude Code and Bolt