Deutsch
Free tool

Storage policy builder for Supabase

Pick a bucket and who may see its files, and get Supabase Storage SQL, a test script, upload code and a fix prompt. Every pattern runs on a real Postgres first.

Runs in your browser. Nothing you enter is sent anywhere.

Who may see the files?
Bucket setting

Every download goes through the policies.

Besides reading, users may…

Replace covers overwriting (upsert) and moving files within the folder.

documents_storage.sql
-- 1. A private bucket: every download, upload and delete goes through the policies below.--    Re-running this updates the visibility of an existing bucket with the same id.insert into storage.buckets (id, name, public)values ('documents', 'documents', false)on conflict (id) do update set public = excluded.public;-- Remove every policy this builder may have added to this bucket before, so changing your choices and running it again leaves nothing behind.drop policy if exists "documents: owner can read" on storage.objects;drop policy if exists "documents: owner can upload" on storage.objects;drop policy if exists "documents: owner can replace" on storage.objects;drop policy if exists "documents: owner can delete" on storage.objects;drop policy if exists "documents: team members can read" on storage.objects;drop policy if exists "documents: team members can upload" on storage.objects;drop policy if exists "documents: team members can replace" on storage.objects;drop policy if exists "documents: team members can delete" on storage.objects;-- 2. Signed-in users see only files in their own folder: the first folder of the path is their user id.create policy "documents: owner can read"  on storage.objects for select  to authenticated  using (    bucket_id = 'documents'    and (storage.foldername(name))[1] = (select auth.uid()::text)  );-- 3. Writes stay inside the same folder. WITH CHECK keeps a replaced, moved or renamed file from landing in another folder.--    Overwriting with upsert: true needs the read, upload and replace policies together.create policy "documents: owner can upload"  on storage.objects for insert  to authenticated  with check (    bucket_id = 'documents'    and (storage.foldername(name))[1] = (select auth.uid()::text)  );create policy "documents: owner can replace"  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 "documents: owner can delete"  on storage.objects for delete  to authenticated  using (    bucket_id = 'documents'    and (storage.foldername(name))[1] = (select auth.uid()::text)  );

Run it in the Supabase SQL editor or add it as a migration. Changed your choices? Run the new version: it removes what an earlier one added for this bucket.

Which pattern fits my bucket?

PatternTypical filesBucketVisitor without accountSigned-in user
Private folder per userinvoices, contracts, ID scans, exportsprivatenothingown folder
Public files, owner uploadsavatars, logos, blog imagespublicopens files by URL, can’t listuploads to own folder
Team foldersdocuments and attachments of a workspaceprivatenothingfolders of their teams
Server onlygenerated reports, backups, importsprivatenothingnothing

When in doubt, start private. A bucket can be made public later; files that were public for a while may already have been copied.

Public or private: what the setting really does

The bucket setting decides more than any policy. Supabase’s docs say Storage skips access control when it serves a file from a public bucket: anyone with a file’s URL can download it, signed in or not. Uploads, listing, moves, copies and deletes still go through the policies.

So a public bucket is right for files meant for everyone and wrong for anything that belongs to one user. Random file names don’t change that: URLs end up in browser history, logs and shared messages. The setting applies to the whole bucket, so keep private and public files in separate buckets. If you pick a private pattern with a public bucket, the builder warns you and writes that warning into the SQL.

The generated SQL creates the bucket with insert into storage.buckets and uses on conflict (id) do update set public = excluded.public. If the bucket exists already, running the script switches it to the setting you chose. The fix page for a public bucket with private files covers switching an existing bucket and its links.

What the generated SQL does

  • bucket_id = '…' is the first condition of every policy. Policies on storage.objects apply to all buckets, so without it a policy could open other buckets.
  • (storage.foldername(name))[1] is the first folder of a file’s path. The builder compares it with (select auth.uid()::text) for per-user folders, or with the team ids of the user’s memberships for team folders. A file at the bucket root has no folder, so the check fails, which is what you want.
  • to authenticated limits every policy to signed-in users. Visitors with only the public key get nothing from these policies.
  • with check on upload and replace decides where a file may be written. On replace it repeats the folder check, so a file can’t be moved or renamed into someone else’s folder.
  • A read policy comes with replace and delete. Supabase’s docs say overwriting with upsert: true needs the select and update permissions besides insert, and that moves and deletes need a select policy too. In the public pattern that read policy is limited to the user’s own folder, so nobody can list everyone’s files.
  • drop policy if exists for every policy name the builder can create for this bucket makes the script safe to run again after you change your choices. Policies of other buckets are left alone.

The team pattern also protects the membership table: members can see their own memberships, which the folder check reads, but nobody can add themselves to a team. The server-only pattern creates no policies at all for the bucket. Your server uses the secret key, which Supabase’s docs say bypasses every Storage policy.

Why the path in your upload code matters

The policies only check the path. The Upload code tab builds it from the signed-in user’s session, for example supabase.storage.from("documents").upload(path, file) with a path that starts with user.id. Don’t take that first folder from a form field or the URL: the policies accept only the user’s own id (or their teams’ ids), so anything else just makes the upload fail. For private buckets the code shows files with a signed URL valid for 60 seconds instead of getPublicUrl, which only works for public buckets.

Uploading to a path that already exists fails unless you pass upsert: true. Supabase’s upload docs also recommend uploading changed files to a new path instead of overwriting, because the CDN can keep serving the old version for a while.

Why old policies can still leak

Policies add up: Postgres combines them with OR. AI builders often create policies that only check the bucket, such as using (bucket_id = 'documents'). Next to the new ones, such a policy still lets every signed-in user read every file. A policy without any bucket_id check is worse: it applies to every bucket. Open the Old policies tab, run the query and drop every policy you don’t recognise.

How to test the result

The Test it tab gives you two snippets for the Supabase SQL editor. The first acts as a real signed-in user (paste an id from Authentication, Users) and counts the files that user can list in the bucket, the second does the same as a visitor. Both only read and change nothing. For a public bucket, remember that the visitor count only covers listing: every file still opens by its URL. For writes, try an upload in your app with a second account.

For the background on buckets, folders and signed URLs, read the Supabase Storage security guide. Tables need their own policies: the RLS policy builder writes them.

Frequently asked questions

Does a public bucket need a read policy?

Not for downloads: Supabase serves files from a public bucket by URL without checking any policy. A broad read policy such as using (bucket_id = ‘avatars’) only adds one thing, the ability to list every file name in the bucket. The builder never adds one; it adds a read policy limited to the user’s own folder only when users may replace or delete files, because those need it.

Why does replacing a file need a read policy?

Supabase’s docs say that overwriting a file with upsert needs the select and update permissions on top of insert, and that overwrites, moves and deletes need a select policy. The builder adds that read policy, limited to the same folder, whenever you allow replacing or deleting.

Folders or the owner_id column?

Supabase records the uploader in the owner_id column of storage.objects, and a policy can compare it with the user’s id. The folder pattern has two advantages: the rule is visible in every path, and it also limits where a user may upload, which an owner check alone does not. Team folders only work with the folder pattern.

Can a user upload into someone else’s folder?

Not with these policies. The upload policy checks the first folder of the new path against the user’s id (or their teams), and the replace policy checks it before and after, so a file can’t be moved into another folder either. Uploads to the bucket root fail, because a file there has no folder.

Can the SQL break my app?

It can if files sit outside the folder pattern, for example at the bucket root or under a name instead of an id: users can no longer reach them. Move them with a server script first. And if older, broader policies exist, they keep working next to the new ones until you drop them; the Old policies tab lists them.

Sources

  1. 1.Storage access control — Supabase Docs
  2. 2.Storage buckets: fundamentals — Supabase Docs
  3. 3.Creating buckets — Supabase Docs
  4. 4.Storage helper functions — Supabase Docs
  5. 5.Storage ownership — Supabase Docs
  6. 6.Standard uploads — Supabase Docs
  7. 7.A01:2025 Broken Access Control — OWASP

Updated