# Supabase Storage policies: the storage.objects pattern

Storage access is governed by RLS on the `storage.objects` table. Agents write policies against their own tables and wonder why uploads 403. Every storage policy targets `storage.objects` and filters on `bucket_id`.

## Checkable procedure

1. Write one policy per operation per bucket: INSERT for uploads, SELECT for downloads, UPDATE and DELETE as needed. A SELECT-only policy means uploads fail with an RLS error that looks like a bucket problem.
2. Key every policy on `bucket_id = 'your-bucket'`. Without the bucket filter, the policy applies to every bucket, which is rarely what you want.
3. For user-owned files, match `auth.uid()` against the object owner or a user-id prefix in the path (`auth.uid()::text = (storage.foldername(name))[1]` is the documented path-prefix pattern). Users then see only their own folder.
4. For INSERT, use WITH CHECK to constrain the path the user may write to, not just USING. Otherwise a user with insert permission can write into another user's folder.
5. Test as the actual roles: anon upload should fail unless you intend public uploads, authenticated upload to own folder should succeed, and cross-user access must fail.

## Quick test

As user A upload to user A's path (should succeed), then try user B's path (must fail). Download as anonymous (must fail for private buckets). Each of the four operations needs its own check.