AleannLab

Open Storage Buckets: Who Can Read Your Users' Uploads?

AleannLab team3 min read

If a bucket is marked public, every file in it can be downloaded by anyone who has or guesses the URL, logged in or not. For avatars and marketing images that is fine. For invoices, ID scans, contracts and chat attachments it is a data leak. Private files belong in a private bucket, behind policies tied to the logged-in user, and are served through short-lived signed URLs.

On this page
  1. What "public" means
  2. Check your buckets
  3. Owner-only policies
  4. Switch a bucket to private
  5. Limit what can be uploaded
  6. The same problem on S3 and Firebase
  7. Test it

AI coding tools pick the public bucket because it is the shortest path to a working image tag. The upload works, the picture shows, and nobody asks what else is in that bucket six months later.

What "public" means

In Supabase Storage a public bucket skips access checks for downloads. The URL has a predictable shape:

code
https://<project>.supabase.co/storage/v1/object/public/<bucket>/<path>

If your app stores files as invoices/<order-id>.pdf or documents/<user-id>/passport.jpg, the paths can be guessed or collected from one leaked link. No key is required.

Making a bucket public does not open uploads or deletes. Those are still controlled by policies. But assistants often add a permissive policy for those too, so check both.

Check your buckets

SQL
select id, name, public, file_size_limit, allowed_mime_types
from storage.buckets;

For each row with public = true, ask whether every file in it is fine to publish on the internet. If the answer is "mostly", the bucket should be private.

Then read the policies on the files table:

SQL
select policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'storage' and tablename = 'objects';

Look for true in qual or with_check, for policies granted to anon, and for policies that check only bucket_id and nothing about the user.

Owner-only policies

The usual pattern is a folder per user: documents/<user-id>/<file>. The policy compares the first folder in the path to the caller:

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

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

Add update and delete policies only if the app needs them. A missing policy means the operation is denied, which is the right default.

Switch a bucket to private

SQL
update storage.buckets set public = false where id = 'documents';

Existing public URLs stop working immediately, so change the code first. Store the file path in your database, not the full URL, and create a signed URL when a user opens the file:

JavaScript
const { data, error } = await supabase.storage
  .from('documents')
  .createSignedUrl(`${user.id}/contract.pdf`, 60); // valid for 60 seconds

window.open(data.signedUrl);

The signed URL is checked against your policies when it is created and expires on its own. A link pasted into a chat stops working a minute later.

Limit what can be uploaded

A bucket that accepts anything will eventually hold something you do not want to serve from your domain. Set limits on the bucket itself, so they hold even when the client code is bypassed:

SQL
update storage.buckets
set file_size_limit = 10485760,  -- 10 MB
    allowed_mime_types = array['application/pdf', 'image/png', 'image/jpeg']
where id = 'documents';

Be careful with SVG and HTML in public buckets. Both can carry scripts.

The same problem on S3 and Firebase

  • AWS S3: keep "Block Public Access" on at the account level. Serve private files with presigned URLs, public assets through CloudFront. Look for bucket policies with "Principal": "*".
  • Firebase Storage: the equivalent of an open bucket is allow read, write: if true; in the storage rules. We cover the rules side in our post on Firebase rules left open.

Test it

  1. Log in as user A, upload a file, copy its URL from the network tab.
  2. Open the URL in a private window with no session. A private file should return an error.
  3. Log in as user B and request A's path through the client:
JavaScript
const { data, error } = await supabase.storage
  .from('documents')
  .download('<user-A-id>/contract.pdf');
// expect an error, not a file
  1. As B, try to list A's folder with .list('<user-A-id>'). Expect an empty result.

Storage is the seventh item in our post on Supabase RLS mistakes, and part of the security checklist for vibe-coded apps. If you would rather have someone check buckets, policies and upload handling for you, see our app rescue and security audit.

All articles →

Ready to discuss your project with us?

idea
*
*
*
I'm interested in...
Web Development
App Development
UX/UI Design
DevOps
Artificial Intelligence And Machine Learning
QA Testing
Mobile Development
Consultation
OutSource
Project budget (USD)
≤ $5K
$10K-$20K
$30K-$40K
$50K-$60K
>$100K
Upload file