---
name: storage-bucket-review
description: Reviews a project's Supabase Storage setup (the buckets that hold uploaded files, the policies on them, and the code that uploads and downloads) for files that anyone can see, replace or delete. Finds public buckets holding private files, policies that let anyone or any signed-in user upload over or delete other people's files, upload buckets with no size or file-type limit, upload code that lets one user overwrite another's file, and private files shared through permanent public links. Use when the user asks whether the files, photos, documents or uploads in their app are protected, who can see or delete them, whether their storage buckets are set up right, or wants a storage check before launch. Explains each problem in plain language with the SQL or code to fix it.
allowed-tools: Read Grep Glob
license: MIT
---

# Supabase Storage review

Read the project's storage buckets, storage policies and upload code, and report where files are open to people who should not have them. Change nothing.

## Rules

- **Read only.** Use Read, Grep and Glob. Do not edit or create files and do not run commands or SQL. Give each fix as SQL or code the user can paste; do not apply it.
- You are reading files, not the live project. Buckets and policies created or changed by hand in the Supabase dashboard do not appear in any file. Say this under "Not checked" every time.
- **Storage only.** This skill covers buckets (`storage.buckets`), the policies on files (`storage.objects`), and the code that uploads, lists, downloads and deletes files. It does not review ordinary database tables or their row-level security; the `supabase-rls-review` skill does that. Do not report table problems here. Point to that skill once, under "Not checked".
- Write for someone who is not an engineer. Say "anyone on the internet" and "any signed-in user", not "the anon role" or "authenticated" on their own. Explain a term the first time you use it.
- Never call the app, a bucket or a piece of code "safe" or "secure". Say what you checked and what you found, for example "only replaces the user's own file".
- Do not guess. If you cannot tell what a bucket holds or who writes to it, put it under "Check this is intended" and say what you could not tell.

## Background you need

A **bucket** is a named folder of files in Supabase Storage. Each file is a row in the table `storage.objects`, with its `bucket_id`, its path in `name` (for example `3f2a…/contract.pdf`), and `owner_id`, the user who uploaded it.

- **Public bucket** (`public = true`): anyone who has a file's address can download it, with no sign-in, forever. Policies do not apply to these downloads. The address is `…/storage/v1/object/public/<bucket>/<path>`, so if paths are predictable, files can be guessed. Uploading, replacing, deleting and listing still go through policies.
- **Private bucket** (`public = false`, the default): every download needs a policy that allows it, or a **signed URL**, a link that stops working after the number of seconds the code chose.
- **Policies on `storage.objects`** decide who may do what with files. Row-level security is on for this table in every Supabase project, so with no policies the browser can do nothing; only server code with the service role key can.
  - `for select`: download from a private bucket, and list file names in any bucket.
  - `for insert`: upload a new file.
  - `for update`: replace or move an existing file.
  - `for delete`: delete a file.
  - `for all`: all four.
  - An upload with `upsert: true` replaces a file that is already at that path; it needs insert, select and update.
  - Supabase also checks the select policies before it deletes, replaces or moves a file: a person can only delete or replace a file they are allowed to see. A public bucket's open downloads do not count as seeing; only a `select` policy does. So an open delete or update policy may be held back today by a select policy that is limited to the owner. It is still a fault: the only thing between strangers and other people's files is that one select policy, and adding any wider read policy later (to list files, for example) opens the door.
- `to anon` means anyone on the internet who is not signed in. `to authenticated` means any signed-in user, and anyone can sign up. `to public`, or no `to` clause, means both. `to service_role` means only server code with the secret service role key, which bypasses policies anyway, so such a policy opens nothing to the browser.
- A policy that does not check `bucket_id = '<bucket>'` applies to **every bucket** in the project.
- A policy ties a file to its owner when its condition compares the file to the signed-in user. These are correct:
  - `(storage.foldername(name))[1] = (select auth.uid())::text` (or `auth.uid()::text`): the first folder in the path must be the user's id. This is the standard pattern and the only one that works for `insert`.
  - `owner_id = (select auth.uid())::text`, or the older `owner = auth.uid()`: the user uploaded the file. Fine for select, update and delete.
- **Limits** live on the bucket: `file_size_limit` (bytes in SQL, such as `10485760` for 10 MB; text such as `"10MiB"` in `config.toml`) and `allowed_mime_types` (a list of file types such as `image/png` or `application/pdf`). With no size limit, the bucket falls back to the project-wide limit (50 MB unless changed). With no type list, any kind of file is accepted.
- **Links in code**: `getPublicUrl(path)` builds a permanent public address; it only works on a public bucket. `createSignedUrl(path, seconds)` builds a temporary one. Downloading through `download()` or a signed URL with a short expiry (minutes or hours) is the right way to serve private files.

## Step 1: Find the storage setup

1. Glob for `supabase/migrations/**/*.sql`, then `supabase/**/*.sql`, then `**/*.sql`. Read every migration in filename order, oldest first.
2. Read `supabase/config.toml` if it exists. Note the `[storage]` section (`file_size_limit`) and every `[storage.buckets.<name>]` section (`public`, `file_size_limit`, `allowed_mime_types`).
3. Grep the whole project, including `src/`, `app/`, `supabase/functions/`, `api/` and `server/`, for: `storage.buckets`, `storage.objects`, `createBucket`, `updateBucket`, `.storage`, `.upload(`, `.update(` on a storage bucket, `.remove(`, `.move(`, `.list(`, `getPublicUrl`, `createSignedUrl`, `createSignedUrls`, `createSignedUploadUrl`, `/storage/v1/object/public/`. Read each file that calls storage.
4. If you find no bucket in SQL, `config.toml` or code, and no storage calls, say so and stop: there is nothing to review. If code uses a bucket that no file defines, review what you can and say under "Not checked" that the bucket was probably made in the dashboard.

## Step 2: Build the final state of each bucket

Migrations run in order and later ones override earlier ones. For each bucket, record the state after the **last** migration:

- where it is defined (`insert into storage.buckets`, `createBucket(...)` in a script, `[storage.buckets.<name>]` in `config.toml`), and any later `update storage.buckets set …` or `delete from storage.buckets`;
- public or private; size limit; allowed file types;
- every policy on `storage.objects` that applies to it: policies naming its `bucket_id`, plus policies with no `bucket_id` check, which apply to all buckets. Apply later `drop policy` and `alter policy` lines. Two policies with the same action add up: if either allows something, it is allowed;
- who uploads to it: browser code (it uses the client made with the public anon or publishable key, usually in `src/`), server code with the service role key (usually in `supabase/functions/` or `api/`), or both;
- what it holds. Judge from the bucket's name, the comments, and what the code puts in it. **Private-looking** files belong to one person or business: invoices, receipts, documents, contracts, IDs, passports, statements, payslips, medical files, attachments to private messages, exports, backups, anything stored under a user's id. **Public by design**: avatars or profile pictures, product photos, logos, blog or marketing images, other files meant to be shown to every visitor.

## Step 3: Check each bucket, its policies and its code

Report as a **problem**:

1. **A public bucket holds private-looking files.** Anyone who has or guesses a file's address can download it without signing in. Put in the same entry any code that hands out permanent links to it (`getPublicUrl`, stored `publicUrl`, hard-coded `/object/public/` addresses), and say that links already sent or saved keep working until the bucket is made private.
2. **Anyone on the internet can upload, replace or delete files.** An `insert`, `update`, `delete` or `all` policy `to anon`, `to public` or with no `to` clause, not limited to `service_role`. This holds even when it checks `bucket_id`.
3. **Any signed-in user can replace or delete other people's files.** An `update`, `delete` or `all` policy `to authenticated` whose condition does not tie the file to its owner: `true`, only a `bucket_id` check, `auth.role() = 'authenticated'`, `auth.uid() is not null`, or a missing condition. If it has no `bucket_id` check, say it reaches **every bucket** and name them.
4. **Any signed-in user can upload anywhere in the bucket.** An `insert` policy `to authenticated` with only a `bucket_id` check, no folder check. People can put files into other users' folders. Lower priority than 3. Do not report it separately when the same bucket is already reported under 2 for insert.
5. **Anyone, or any signed-in user, can list or download private files.** A `select` policy on a private bucket of private-looking files that is not tied to the owner, `to anon`, `to public`, no `to` clause, or `to authenticated` with only a `bucket_id` check.
6. **A bucket people upload to from the browser has no size limit or no file-type limit.** Give one entry per bucket and say which limit is missing. Someone can fill your storage (and your bill) with huge files, or upload any kind of file. Do not report this for buckets that only server code writes to.
7. **Upload code builds the path from what the user typed or chose, without the user's own folder.** For example `upload(file.name, …)`, a path made from a form field or title, or `` `${bucket}/${file.name}` ``. Two users who pick the same file name collide; with `upsert: true`, or with an update policy that is not owner-only, one user's upload replaces another's file. Report the code even if a policy problem in the same bucket is also reported: both need fixing.
8. **Private files are shared through long-lived links.** `getPublicUrl` or `/object/public/` addresses for a private-looking bucket that is not already reported under 1, or `createSignedUrl` with an expiry longer than 7 days (604800 seconds) for private-looking files, or signed links saved in the database for later use.

For checks 2, 3 and 7, look at the bucket's `select` policies before you write "What this means", and describe what is possible **today**:

- If the select policies let the person see other people's files (they are open, or not tied to the owner), say plainly that they can replace or delete those files now.
- If every select policy that reaches the bucket is tied to the owner, or the bucket has none, still report the problem, and say what holds it back: "Today this is held back only by the read policy `<name>`, which lets people see just their own files; Supabase checks it before a delete or replace. Any wider read policy added later would let anyone signed in delete other people's files." For check 7 in that case, say the second person's upload fails with an error instead of replacing the file, and that it would replace it if the read policy were ever widened.
- Do not claim that a file can be deleted, replaced or overwritten when the select policies in the files you read prevent it.

Report under **"Check this is intended"**, not as a problem:

- A `select` policy on a **public** bucket that lets anyone list its files. Downloads are open anyway, but listing shows every file name at once.
- A bucket whose contents or uploaders you could not work out.
- An upload or download in code to a bucket that no file defines.

Do **not** report:

- A public bucket that holds public-by-design files (avatars, product photos), or `getPublicUrl` on such a bucket. Mention it under "Looks right" with its limits, if any.
- Policies limited `to service_role`, and buckets that only server code writes to. A bucket written only by server code needs no size or type limit from this review.
- Policies tied to the owner as described in Background, on any action.
- `upsert: true` when the path starts with the user's id (`` `${user.id}/…` ``) and the bucket's policies check that folder. Replacing your own file is the point.
- Short-lived signed URLs (`createSignedUrl(path, 60)`, `3600` and similar) or `download()` for private files.
- A private bucket with no browser policies. It is locked to the browser; say so under "Looks right".
- Server code that reads the service role key from the environment. Whether that key is exposed is a secrets question, not a storage one.
- Anything about ordinary database tables, such as missing row-level security on `public.invoices`.

## Output

Reply with this and nothing before it.

````
Supabase Storage review: <N> problem(s) found in <M> bucket(s) reviewed

## Problems

1. `<bucket>`: <the problem in one plain sentence>
   Where: `<file>:<line>`
   What this means: <who can do what to whose files, in plain words>
   Paste this to your builder: "<one plain-language instruction for Lovable, Bolt, Replit or a similar AI builder>"
   Fix:
   ```sql
   <SQL to paste into a new migration or the SQL editor, or the code change in the file's own language>
   ```

## Check this is intended

- `<bucket>`: <what is open and to whom, or what you could not tell> (`<file>:<line>`)

## Looks right

- `<bucket>`: <public or private, limits, who can do what, in one line>

## Not checked

- The live project. This review read files only. Buckets and policies created or changed by hand in the Supabase dashboard do not show up here.
````

- `<M>` is every bucket you reviewed, including those with nothing wrong.
- Order problems by damage: private files anyone on the internet can download, then anyone on the internet can upload, replace or delete, then any signed-in user can replace or delete, then upload code that overwrites, then long-lived links, then missing limits, then the rest.
- One numbered problem per bucket and fault. Never merge two faults into one entry, even in the same bucket: a policy fault (checks 2 to 5) and an upload-code fault (check 7) are always separate entries. A policy with no `bucket_id` check is one problem; list the buckets it reaches inside that entry.
- Decide the full list of problems before you write the headline. `<N>` must equal the number of numbered entries under Problems.
- Most readers change their app by prompting an AI builder (Lovable, Bolt, Replit), so every problem gets a "Paste this to your builder:" line before its Fix. It is one line (a sentence or two) in quotes, in plain words, and:
  - asks for the **same** fix as the SQL or code below it, not a different or partial one;
  - names the bucket, and the file or policy name when the fix touches one (for example "in `src/pages/Documents.tsx`", "the storage policy \"Allow delete\"");
  - keeps every warning the fix carries, such as "ship the new upload policy and the upload code change together, or uploads will fail", or "the old public links will stop working";
  - never asks the builder to switch anything off: not row-level security, not a check, not the bucket, not uploads, and never to delete files. When an open policy goes, ask the builder to **replace** it with the owner-only one in the same step, so the app keeps working;
  - ends by asking the builder to show the change before applying it, for example "Show me the SQL before you run it."
- Write fix SQL that is complete and safe to paste:
  - Make a bucket private: `update storage.buckets set public = false where id = '<bucket>';`, plus an owner-only `select` policy so the app can still create signed links, plus the code change from `getPublicUrl` to `createSignedUrl(path, 60)`. Warn that every public link already shared or saved will stop working, and that anything downloaded while the bucket was public may already have been copied.
  - Replace a policy: `drop policy "<name>" on storage.objects;`, then `create policy … on storage.objects for <action> to authenticated` with `bucket_id = '<bucket>' and (storage.foldername(name))[1] = (select auth.uid())::text` in `using` (select, update, delete) or `with check` (insert), and both on update. Use the bucket's real name.
  - Add limits: `update storage.buckets set file_size_limit = <bytes>, allowed_mime_types = array['…'] where id = '<bucket>';` with a size and types that fit what the app accepts. If the bucket is defined in `config.toml`, give the `config.toml` lines too.
  - Fix an upload path: show the changed line, with the path starting `` `${user.id}/` `` and a random part such as `crypto.randomUUID()`, and `upsert` removed unless the user must replace their own file. Warn that the folder policy and the code change must go out together, or uploads will fail.
- When a fix removes access the app relies on (for example dropping an open delete policy the app's delete button uses), include the owner-only policy that replaces it.
- If there are no problems, write `Supabase Storage review: 0 problems found in <M> bucket(s) reviewed`, write "None." under Problems, and keep the other sections. Do not invent a problem.
- Always include these under "Not checked", plus anything else you could not see:
  - Buckets and policies changed by hand in the Supabase dashboard, and whether every migration has been applied to the live project.
  - Whether `config.toml` bucket settings reached the live project. They apply to local development and to `supabase seed buckets`; check the bucket in the dashboard under Storage.
  - Ordinary database tables and their row-level security, such as tables that store file paths or links. Run the `supabase-rls-review` skill for those.
  - Files already in the buckets, and who may have downloaded them.
  - Who can call server functions that write with the service role key. This review notes them but does not check their own sign-in checks.
  - File-type limits trust the type the uploader declares; they do not inspect the file's contents.

<!--
MIT License

Copyright (c) 2026 PT Maverick Rintis Karya

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
