high · M3 · MASVS-AUTH-2 · PTKD-BACKEND-SUPABASE-STORAGE-OPEN-POLICY
Supabase Storage policy lets anyone upload, overwrite or delete files
A policy on storage.objects allows inserts, updates or deletes with a condition that does not tie the file to the caller (true, only the bucket name, or only "signed in"). Anyone with the app's anon key, or any user, can then upload files to your bucket, replace other users' files or delete them.
How it is exploited
avatars has `for insert to public with check (bucket_id = 'avatars')`. A script with the anon key uploads gigabytes of files, or malware with a user's file name, to your bucket; with the matching update policy it overwrites every user's avatar.
Why it matters
Storage abuse and bills, defacement, malware hosted under your domain, and users' files replaced or deleted.
How to fix it
- Use one folder per user and check it: (storage.foldername(name))[1] = (select auth.uid())::text.
- Grant writes to the authenticated role only.
- Keep public read only for buckets that are meant to be public.
migration
create policy "own folder upload" on storage.objects for insert to authenticated
with check (bucket_id = 'avatars' and (storage.foldername(name))[1] = (select auth.uid())::text);Does your app have this?
PTKD checks your build or your source project for PTKD-BACKEND-SUPABASE-STORAGE-OPEN-POLICY and every other check in this knowledge base.
Scan your appReferences
Related checks (M3)
- Permissive CORS with credentials
- State-changing request succeeded without authentication
- Weak JWT observed on the wire
- Biometric authentication not bound to a cryptographic key
- Premium access is stored on the phone and trusted (heuristic)
- Firebase rules trust an email address nobody verified
- Firebase security rules open to everyone
- Users can make themselves admin or premium in Firestore