Deutsch
GuideSupabase · Storage

Supabase Storage security: buckets, policies and signed URLs

How to keep files in Supabase Storage private: public vs private buckets, per-user folder policies on storage.objects and short-lived signed URLs, with tested SQL.

By Tim GeithnerPublished 6 min read

Short answer

In Supabase Storage, a public bucket serves every file to anyone who has the URL, with no policy check. Put private files in a private bucket and control access with RLS policies on storage.objects, typically by keeping each user’s files in a folder named after their user ID and comparing (storage.foldername(name))[1] with auth.uid(). Share a private file with a short-lived signed URL created on the server.

Ask an AI about this page:ChatGPTClaude

On this page

Key takeaways

  • Public bucket = public files. Anyone with the URL can download, no policy is checked. Only use it for avatars, logos and other content meant for everyone.
  • Private files belong in a private bucket with RLS policies on storage.objects.
  • The standard pattern: each user’s files live under <user-id>/… and every policy checks (storage.foldername(name))[1] against auth.uid().
  • A policy that only checks bucket_id lets every signed-in user read and overwrite every file in the bucket.
  • Share private files with short-lived signed URLs created on the server. They can’t be revoked one by one.

How Storage decides who gets a file

Supabase Storage keeps the metadata of every file as a row in the storage.objects table, with the bucket in bucket_id and the path in name. Access is controlled with the same mechanism as your own tables: row level security policies on storage.objects. Supabase’s docs say policies there control every file operation, from upload and download to listing, moving and creating signed URLs. Without a policy, nothing is allowed: Storage accepts no uploads to a bucket until a policy permits them.

Two things skip those policies:

  1. Public buckets. In a bucket marked public, downloads bypass access control. Anyone who has a file’s URL can fetch it, signed in or not. Uploads, deletes, moves and copies are still checked.
  2. Signed URLs and the secret key. A signed URL works without any policy until it expires. The secret key (or legacy service_role key) bypasses RLS for all Storage APIs.

So the first question for every bucket is not “which policies?” but “should this be public at all?”

Public or private: decide per bucket

ContentBucketWhy
Profile pictures, logos, blog imagespublicmeant to be seen, better CDN caching
Invoices, ID scans, contracts, exportsprivatemust only reach the owner
User uploads you haven’t reviewedprivateyou don’t know yet what is in them
AI-generated files per userprivatemay contain the user’s data

The setting applies to the whole bucket, not to single files. A common mistake in AI-built apps is one bucket called uploads that is public because avatars “didn’t show up” without it, and that later also receives invoices. Our fix page for a public bucket with private files covers moving them out.

Check your buckets in the SQL Editor:

Which buckets are public?
select id, public
from storage.buckets
order by public desc, id;

Create a private bucket in a migration like this:

A private bucket for documents
insert into storage.buckets (id, name, public)
values ('documents', 'documents', false);

The policy that looks right but isn’t

AI builders often generate policies that only check the bucket:

VulnerableBucket-only policies
create policy "Signed-in users can upload"
  on storage.objects for insert
  to authenticated
  with check (bucket_id = 'documents');

create policy "Signed-in users can read"
  on storage.objects for select
  to authenticated
  using (bucket_id = 'documents');

The bucket is private and visitors without an account get nothing, so it feels safe. But every signed-in user can now read every file in the bucket and upload into any path. In our test, Bob could list Alice’s contract and write a file into Alice’s folder. With open sign-ups, “signed in” means “anyone with an e-mail address”.

Per-user folders with storage.foldername()

The pattern Supabase documents is to put each user’s files in a folder named after their user ID, for example 11111111-…/invoices/2026-11.pdf, and check that folder in every policy. storage.foldername() returns the folders of a path as an array:

What foldername returns
select storage.foldername('11111111-1111-1111-1111-111111111111/invoices/2026-11.pdf') as folders;
-- {11111111-1111-1111-1111-111111111111,invoices}

Postgres arrays start at 1, so (storage.foldername(name))[1] is the top folder. A file at the bucket root has no folder; the expression is null and the check fails, which is what you want. Here are the four policies for a private documents bucket:

SafeOwner-only access to a private bucket
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.uid()::text)
  );

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

create policy "Users replace their own files"
  on storage.objects for update
  to authenticated
  using (
    bucket_id = 'documents'
    and (storage.foldername(name))[1] = (select auth.uid()::text)
  )
  with check (
    bucket_id = 'documents'
    and (storage.foldername(name))[1] = (select auth.uid()::text)
  );

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

What each part does:

  • bucket_id = 'documents' keeps the policy from accidentally opening other buckets.
  • auth.uid()::text is needed because foldername returns text and auth.uid() returns a UUID.
  • with check on update stops a user from moving their file into someone else’s folder. A rename is an update of name.
  • Upsert (overwriting with upsert: true) needs the select and update policies in addition to insert, according to Supabase’s docs.

In your upload code, build the path from the session, never from user input: ${user.id}/${fileName}.

Folders or the owner column?

Supabase’s docs also show a second pattern: compare the owner_id column of storage.objects, which records who uploaded the file, with the user’s ID. That works well for “only the uploader may read this”. The folder pattern has two advantages for most apps: the rule is visible in every path, so you can spot a wrong upload in the dashboard, and it also limits where a user may upload, which an owner check alone does not. Whichever you choose, use it in all four policies.

Two things undo any pattern. The first is the secret key in browser code: it bypasses every Storage policy, so a service_role key in the frontend turns a private bucket into a public one. The second is a missing select policy on a table that stores file paths: if users can read every row of an attachments table, they learn every path, and with an open bucket that is all they need. Protect those tables with the owner policies from the row level security guide.

Check the policies you have

All policies on storage.objects
select policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'storage' and tablename = 'objects'
order by cmd, policyname;

For each private bucket you should see one policy per action you use, and every qual or with_check should mention both the bucket and the owner check. A condition that is just bucket_id = '…' is the pattern above. You can test what one user sees with the transaction technique from our guide on testing RLS policies, against storage.objects instead of your own table.

Signed URLs: share a private file for a short time

A private file can’t be fetched with a plain URL. You have two options: download it with the user’s session (the client library sends the user’s token, and your select policy decides), or create a signed URL, which works for anyone who has it until it expires.

supabase/functions/download/index.ts (sketch)
// Runs on the server with the user's session, so the select policy applies.
const { data, error } = await supabase.storage
  .from("documents")
  .createSignedUrl(`${user.id}/invoices/2026-11.pdf`, 60); // valid for 60 seconds

Rules that keep signed URLs safe:

  • Keep the expiry short. The second argument is in seconds. For a download button, a minute is plenty.
  • Create them for the signed-in user, not with the secret key and a path from the request. With the user’s session, Storage checks your select policy before it signs; with the secret key it signs any path you pass.
  • Treat the URL like a password while it is valid. Don’t log it, don’t put it in analytics, don’t e-mail long-lived links.
  • You can’t revoke one URL. Supabase’s docs say to delete, move or rename the file to invalidate it, or rotate the URL signing key to invalidate all of them.

A fix prompt for your AI builder

Lock down a Supabase Storage bucket

Review Supabase Storage in this project. List every bucket and whether it is public. For any public bucket that receives user uploads other than avatars or public images, create a new private bucket in a migration and tell me which code uploads to the old one.

For the private bucket documents (replace with the bucket name), replace all existing policies on storage.objects for that bucket with four policies for the authenticated role only: select, insert, update and delete, each requiring bucket_id = ‘documents’ and (storage.foldername(name))[1] = (select auth.uid()::text). The update policy needs both USING and WITH CHECK.

Change the upload code so the path always starts with the signed-in user’s id from the session. Replace any getPublicUrl call for private files with createSignedUrl with an expiry of at most 300 seconds, created with the user’s session, not the service role key. Show me the migration before applying it.

Frequently asked questions

What is the difference between a public and a private bucket in Supabase?

In a public bucket, downloads skip access control: anyone with a file’s URL can fetch it. Uploads, deletes, moves and copies still go through your policies. In a private bucket every operation, including downloads, is checked against the RLS policies on storage.objects.

Can I make one file in a public bucket private?

No. The public setting applies to the whole bucket. Move private files to a separate private bucket and serve them with signed URLs or authenticated downloads.

How long should a signed URL be valid?

As short as your use case allows: seconds to minutes for a download button, longer only when you must. The expiry is set in seconds, anyone holding the URL can use it until then, and Supabase can’t revoke a single signed URL. You would have to delete, move or rename the file.

Do I need policies on storage.buckets?

Only if your frontend calls bucket methods such as creating or listing buckets. File operations need policies on storage.objects only. Most apps create buckets in a migration and need no client policy on storage.buckets.

Sources

  1. 1.Storage access control — Supabase Docs
  2. 2.Storage buckets — Supabase Docs
  3. 3.Serving assets from Storage — Supabase Docs
  4. 4.Storage helper functions — Supabase Docs
  5. 5.JavaScript reference: createSignedUrl — Supabase Docs

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