StoicBuilder

HandbookIII the CastraSafe file uploads

IIIthe Castra, Stay in control

Safe file uploads

1 min readUpdated 28 November

In plain words

A safe upload checks the file's type and size, stores it away from your code with access rules, and never trusts the name or type the browser claims.

Where you see it

Guildhall lets members upload a profile picture to a Supabase Storage bucket. With no size limit or type list, someone can upload a 2 GB video, or a pile of files that have nothing to do with avatars, and use your storage as free hosting.

supabase/migrations/20261202_avatars.sqldatabase
create policy "Members upload their own avatar"on storage.objects for insertto authenticatedwith check ( bucket_id = 'avatars' and (storage.foldername(name))[1] = (select auth.uid())::text);
Each member can upload only into a folder named after their own user ID.

What goes wrong

  1. Checking the file type only in the browser

    accept="image/*" filters the file picker, not the upload. Set allowed types and a size limit on the bucket or the server too.

  2. Keeping the uploaded file name

    Names like ../../config.js or a 300-character string can overwrite files or break pages. Generate your own name and keep the original only as a label.

  3. Putting private files in a public bucket

    Invoices and ID scans in a public bucket are readable by anyone who gets the link. Use a private bucket and signed URLs that expire.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Set a file size limit and a list of allowed file types on every Supabase Storage bucket, and add storage policies so users can only upload into their own folder. Keep anything personal in a private bucket served through signed URLs that expire, and rename files on upload.

Quick check

Sign in to earn +10 XP for it

Your upload field has accept="image/*". Can someone still upload a .exe file?

Got a prompt that touches safe file uploads?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.