Fix guides · Lovable, Bolt, Cursor, Claude Code, Replit, v0 ·
Fix Supabase Storage "permission denied" and 403 errors
permission denied for table storage.objects
Supabase Storage blocks uploads or downloads because Row Level Security (RLS) on the single storage.objects table doesn't allow the action. Storage uses the same RLS system as database tables, filtered by the bucket_id column. A missing policy usually returns "new row violates row-level security policy" (or a generic 403). A missing table GRANT (rare) returns "permission denied for table storage.objects". Size or MIME limits return 413 or 400 with different messages. Uploads fail when there's no INSERT policy for your role on the bucket, the file path doesn't match the policy's folder check, or the file exceeds limits.
Common causes – and how to tell which one you have
1. No INSERT policy for authenticated users on the bucket
How to tell: In Storage → Policies, the bucket has no policies, or only SELECT/DELETE/UPDATE but no INSERT for authenticated. The Network tab shows 403 or 401, often with "new row violates row-level security policy" or a generic forbidden response.
Fix: Add an INSERT policy with WITH CHECK (bucket_id = 'your-bucket' AND auth.uid()::text = (storage.foldername(name))[1]) so users can only upload to their own folder.
2. Upload path doesn't match the policy's folder check
How to tell: The policy expects files under the user's ID folder (auth.uid() = foldername(name)[1]), but your code uploads to a flat path like 'avatars/profile.jpg' or a different folder structure.
Fix: Either change the upload path in your code to include the user ID prefix (e.g., `${user.id}/${file.name}`), or adjust the policy's WITH CHECK to match your actual folder structure.
3. File exceeds bucket size limit or has disallowed MIME type
How to tell: The error is 413 "The object exceeded the maximum allowed size" (file too large) or 400 "Invalid MIME type" (disallowed type). The bucket settings show a file_size_limit (default 50MB) or an allowed_mime_types array that excludes your file type.
Fix: In the Supabase Dashboard → Storage → your bucket, increase file_size_limit or add the MIME type to allowed_mime_types. Or validate client-side before upload.
4. Request runs as anon instead of authenticated
How to tell: The upload works when you're logged in locally but fails after deploy, or the Network request shows no Authorization header. The client created with the anon key can't satisfy authenticated policies.
Fix: Ensure the Supabase client is created with the user's session (createBrowserClient from @supabase/ssr in Next.js, or the regular createClient in client-side code). The client attaches the access token automatically once a session exists — you don't need a manual getSession() call before upload.
5. CORS preflight not handled by the Storage API
How to tell: Browser console shows a CORS error before the 403. The OPTIONS preflight to the storage endpoint fails.
Fix: Supabase Storage handles CORS automatically for allowed origins. If it fails, check the browser console for the exact CORS error and verify the request origin is allowed by the Storage API. Custom domains may need CORS configuration in your CDN or hosting layer.
How to fix it
- Open the browser DevTools Network tab and trigger the failing upload. Click the request to supabase.co/storage/v1/object/... and note the status (403) and any error body (often {"message": "permission denied for table storage.objects"}).
- In the Supabase Dashboard, go to Storage, select your bucket, and check the Policies tab. Note which roles (anon, authenticated) have INSERT, SELECT, UPDATE, DELETE policies and what their USING/WITH CHECK expressions are.
- Check the bucket settings: File size limit and Allowed MIME types. A 413 "The object exceeded the maximum allowed size" means the file is larger than the bucket limit (default 50MB).
- If no INSERT policy exists for authenticated users on this bucket, create one in the SQL Editor: create policy "Users upload own files" on storage.objects for insert to authenticated with check ( bucket_id = 'your-bucket' and auth.uid()::text = (storage.foldername(name))[1] ); This requires upload paths like <user-id>/filename.ext.
- Add matching SELECT and DELETE policies with the same folder check (using instead of with check for SELECT and DELETE). For UPDATE, add both USING (which row can be updated) and WITH CHECK (which row can remain after the update). For public read access, add a policy to anon, authenticated with using (bucket_id = 'your-bucket').
- If your upload path doesn't match the folder pattern (e.g., you upload to 'avatars/file.jpg' but the policy expects '<user-id>/file.jpg'), either change the upload path in your code to include the user ID prefix, or adjust the policy to match your folder structure.
- Test the upload again. Check the Network tab: the request should return 200/201 with the uploaded object metadata.
Using Lovable, Bolt or v0?
In Lovable or Bolt, tell the AI: "Supabase Storage upload returns 403 permission denied. Add an INSERT policy on storage.objects for authenticated users that checks bucket_id and auth.uid() = foldername(name)[1]. Make sure the upload path uses the user ID as the first folder." Then test the upload in the preview and check the Network tab.
Using Cursor, Claude Code or Windsurf?
Ask Cursor or Claude Code to read the current storage policies (SQL: SELECT * FROM pg_policies WHERE tablename = 'objects' AND schemaname = 'storage'), compare them with the upload path in the code, and generate the missing policy SQL. Have it verify by uploading a test file and confirming 200 response.
The “fix” to avoid
Agents often disable RLS on storage.objects (ALTER TABLE storage.objects DISABLE ROW LEVEL SECURITY) or add a policy with WITH CHECK (true). This makes the upload work but lets anyone with your anon key upload, overwrite, or delete any file in the bucket. Keep RLS on and scope policies to the user's folder.
Copy-paste fix prompt for your AI coding tool
Paste this into Cursor, Claude Code, Lovable or Bolt:
Supabase Storage upload fails with 403 and "permission denied for table storage.objects". Check: 1) Does the bucket have an INSERT policy for authenticated users? 2) Does the policy's WITH CHECK match the actual upload path (bucket_id and folder pattern)? 3) Are file size and MIME type within bucket limits? 4) Does the client send the user's auth token (supabase.auth.getSession) so the request runs as authenticated? Fix the policy or the upload path, don't disable RLS on storage.objects. Show me the SQL for the new policy and verify the upload works.
Questions people ask
Why is the error 'permission denied for table storage.objects' and not my bucket name?
Supabase Storage uses a single table storage.objects for all buckets. The bucket is identified by the bucket_id column. RLS policies run on that table, so the error names the table.
Can I use the service_role key to bypass Storage RLS?
Technically yes, but never in browser code. The service_role key bypasses all RLS and gives full access to every bucket. Only use it in server-side code (API routes, Edge Functions) for admin operations. In client code, always use the anon key with proper user-scoped policies.
How do I allow public read access to uploaded files?
Add a SELECT policy on storage.objects for anon, authenticated with USING (bucket_id = 'your-bucket'). This lets anyone read files in that bucket without authentication. The upload policy still requires authenticated with the folder check.
Official documentation
- Supabase: Storage access control (RLS policies)
- Supabase: Storage buckets and files
- nikofischer.com: Supabase Storage file upload guide
- Supabase KB: Database API 42501 errors