5 min read

Supabase Storage bucket RLS — buckets need policies too

Storage buckets default-allow read in tutorials. Add RLS policies + signed URLs for downloads.

Supabase Storage has its own RLS layer. Tutorials often skip; default-public buckets leak everything.

What it is

Storage = the Supabase file-storage service. Buckets need RLS policies on storage.objects, not just on regular tables.

Vulnerable example

-- Public bucket — every file readable
create policy "anyone_reads" on storage.objects for select using (true);

Fixed example

-- Per-user-scoped bucket
create policy "users_read_own_files" on storage.objects for select
  using (
    bucket_id = 'user-uploads'
    and auth.uid()::text = (storage.foldername(name))[1]
  );
create policy "users_insert_own_files" on storage.objects for insert
  with check (
    bucket_id = 'user-uploads'
    and auth.uid()::text = (storage.foldername(name))[1]
  );
-- Use signed URLs for downloads (never public-bucket)

How Securie catches it

Securie findingcritical
supabase/migrations/0042_orders_rls.sql:14

Supabase Storage bucket RLS

Supabase RLS specialist scans storage policies + flags default-public + missing-per-user-scope.

Suggested fix — ready as a PR
-- Per-user-scoped bucket
create policy "users_read_own_files" on storage.objects for select
  using (
    bucket_id = 'user-uploads'
    and auth.uid()::text = (storage.foldername(name))[1]
  );
create policy "users_insert_own_files" on storage.objects for insert
  with check (
    bucket_id = 'user-uploads'
    and auth.uid()::text = (storage.foldername(name))[1]
  );
-- Use signed URLs for downloads (never public-bucket)
Catch this in my repo →Securie scans every PR · ships the fix as a one-click merge · free during early access

Checklist

  • RLS enabled on storage.objects
  • Per-user folder scoping
  • Signed URLs for downloads (1h TTL max)
  • Strict content-type on upload

FAQ

Public bucket for landing-page assets?

OK if intentional. Mark bucket public explicitly + understand the trade-off.

Related guides