How Do You Secure Supabase Storage in a Vibe-Coded App?
Supabase Storage looks private by default, but vibe-coded apps routinely ship with open buckets, missing RLS, and service keys in client code. Here's the fix.
Supabase Storage security is one of the most overlooked surfaces in vibe-coded apps. When a founder builds a product with Lovable, Bolt, or Cursor and wires up file uploads, the AI scaffolds the connection in minutes — but the access controls are often left in a state that exposes every uploaded file to any user who can guess the URL. Unlike Supabase table RLS, which locks down database rows, Storage requires a separate set of policies on storage.objects — and those policies do not write themselves.
This post is a practical guide for builders who already have a Supabase and storage integration running and want to understand exactly what is exposed, what the fix is for each issue, and how to verify it works. We cover bucket visibility, RLS policies on the objects table, signed URLs, file type enforcement, and the service role key problem that shows up in almost every vibe-coded app audit.
How Supabase Storage Works (and What's Exposed Without Policies)
Supabase Storage is built on top of Postgres and S3-compatible object storage, with a REST API in front. Files are organized into buckets, and within buckets into paths. When you create a bucket, it defaults to private — but private in Supabase's model means that every file operation requires a valid JWT and a matching RLS policy on the storage.objects table. If you create a private bucket with no policies, no operation succeeds at all. If you accidentally create a public bucket, every file is readable by anyone who knows the URL — no authentication required.
- →Public buckets: any file is served over a publicly accessible URL at <project-ref>.supabase.co/storage/v1/object/public/<bucket>/<path>. There is no authentication check on reads. If a user uploads a profile photo to a public bucket, that photo is reachable by anyone on the internet — including bots that enumerate predictable paths.
- →Private buckets: reads and writes require a valid JWT (the anon key for unauthenticated flows, or the user JWT for authenticated users) and a matching RLS policy on storage.objects. Without a policy, even authenticated users are blocked.
- →The service role key bypasses everything: a request made with the service role key skips all RLS checks and can read, write, or delete any file in any bucket. This key should never appear in client-side code, Next.js NEXT_PUBLIC_ variables, or mobile app bundles.
- →Bucket creation happens at setup time and is easy to get wrong: Lovable, Bolt, and Cursor-generated code often creates buckets inline and may default to public depending on how the AI scaffolds the connection. Always verify the bucket's public or private status in the Supabase dashboard under Storage before you launch.
The Public Bucket Mistake: What It Exposes and How to Check
The most common Supabase Storage security mistake in vibe-coded apps is a public bucket used for user-specific files — profile photos, ID documents, uploaded invoices, private notes. The developer created a public bucket for convenience because it simplifies the SDK calls, and now every file in it is accessible to anyone who requests the URL. There is no RBAC, no ownership check, no authentication gate of any kind on reads.
- →To check: open the Supabase dashboard, navigate to Storage, and inspect your buckets list. Each bucket row shows whether it is Public or Private. If any bucket storing user-specific data shows as Public, it needs to be fixed before real user data enters it.
- →To fix an existing public bucket via SQL: `UPDATE storage.buckets SET public = false WHERE name = 'your-bucket-name';` Run this in the Supabase SQL editor. The change is immediate — all existing public URLs for files in that bucket stop working as soon as the update lands.
- →Breaking change to plan for: changing a public bucket to private immediately 404s every existing public URL you have been handing out or storing in your database as strings. Migrate those references to signed URL generation before you make the switch. If you have stored file paths in a table, those paths now need to be passed through a signed URL generator before serving.
- →Legitimate public buckets: if the bucket genuinely serves public assets — landing page images, product photos, public documentation attachments — a public bucket is correct. The mistake is mixing user-uploaded private files into the same public bucket. Separate public assets from private user uploads into distinct buckets.
Writing RLS Policies on storage.objects for Private Buckets
For private buckets, access is controlled by RLS policies on the storage.objects table — not on the bucket itself. This uses the same Postgres RLS system as the rest of your application, but it applies to file metadata rows rather than your own tables. The standard pattern for user-private files is a folder-prefixed path: each user's files live at a path prefixed by their user ID, and the policies enforce that only the owner can read and write to their own prefix.
- →Required policies for a user-private bucket: SELECT (read), INSERT (upload), UPDATE (replace), and DELETE. Each policy checks `auth.uid() = (storage.foldername(name))[1]::uuid` — meaning the first segment of the file path must match the authenticated user's ID. Upload files to paths like user-uploads/{auth.uid()}/invoice.pdf and this condition enforces ownership automatically.
- →Policy template for SELECT: `CREATE POLICY user_read_own_files ON storage.objects FOR SELECT USING (bucket_id = 'user-uploads' AND auth.uid() = (storage.foldername(name))[1]::uuid);`
- →Policy template for INSERT: `CREATE POLICY user_upload_own_files ON storage.objects FOR INSERT WITH CHECK (bucket_id = 'user-uploads' AND auth.uid() = (storage.foldername(name))[1]::uuid);`
- →If you manage files on behalf of a user from a server-side route — a Next.js Route Handler or Edge Function — use the user's JWT to initialize the Supabase client rather than the service role key. The RLS policy checks against the JWT's subject claim. A service role key bypasses RLS entirely and would allow any server action to touch any user's files, which removes the safety net from your server-side logic.
- →Test your policies with a second test account: upload a file as user A, then sign in as user B and try to read that file by constructing its path. If your policy is correct, the read fails. If it succeeds, the policy has a gap — the wrong condition, or the path prefix is not being enforced.
Using Signed URLs for Temporary, Revocable File Access
Signed URLs are the correct mechanism for sharing private files in Supabase Storage. Instead of making a bucket public, you generate a time-limited URL that includes a cryptographic token Supabase validates on each request. The URL expires after the duration you specify — 1 hour for a document the user is about to view, 24 hours for a file you are including in a notification email. Run DeployReady first on any app that handles file uploads — it flags service key exposure in environment variables, public bucket misconfigurations, and missing security headers automatically.
- →Generating a signed URL: `const { data, error } = await supabase.storage.from('user-uploads').createSignedUrl(filePath, 3600);` The second argument is the expiry in seconds. Return the signed URL to the client and use it for the display or download. Never store long-lived signed URLs in your database — generate them fresh on each request.
- →Authorization happens at generation time: Supabase validates the caller's JWT when you call createSignedUrl. This means you should generate signed URLs server-side, after applying your own authorization check that the requesting user owns the file at that path. The resulting URL can then be used by anyone who holds it, without an active session — which is intentional when you need to serve files in an email or an img tag.
- →Signed URL revocation: Supabase signed URLs use a separate internal signing key and do not support individual revocation via the dashboard or SDK. If you need a file to stop being accessible immediately — account deletion, compliance request — you must delete the object from Storage as well as communicate the revocation to any downstream caches.
- →Cache-control at upload time: set a short cache-control value when uploading sensitive files. A URL that has expired at the Supabase level can still be cached in a browser or CDN and served from cache. Use `cacheControl: '0'` or a low value for files that may need fast invalidation, particularly for documents with legal, medical, or financial sensitivity.
Restricting File Types and Sizes at the Bucket Level
File type validation and size limits are enforced by the Supabase Storage API when you configure them on the bucket — before the file is written to storage. This enforcement happens on the server side and cannot be bypassed by modifying a client request, unlike an HTML accept attribute or a client-side type check.
- →Size limits: set fileSizeLimit in bytes at bucket creation. For user profile photos, 5 MB (5242880 bytes) is generous. For PDF uploads, 10 MB is reasonable. Without a limit, a user can upload a file large enough to exhaust your storage quota or trigger unexpected egress charges.
- →MIME type allowlists: set allowedMimeTypes as an array at bucket creation — ['image/jpeg', 'image/png', 'image/webp'] for photo uploads. Storage rejects any upload whose Content-Type header does not match. This prevents a user from renaming an executable to .jpg and uploading it.
- →SDK example at bucket creation: `await supabase.storage.createBucket('profile-photos', { public: false, fileSizeLimit: 5242880, allowedMimeTypes: ['image/jpeg', 'image/png', 'image/webp'] });`
- →Updating limits on an existing bucket via SQL: `UPDATE storage.buckets SET file_size_limit = 5242880, allowed_mime_types = ARRAY['image/jpeg', 'image/png'] WHERE name = 'profile-photos';`
- →Server-side MIME validation is still required: the Content-Type header is caller-controlled and can be spoofed. For files that will be rendered or served to other users, validate the actual file signature (magic bytes) in a server-side Route Handler or Edge Function before accepting the upload path, particularly for files stored in shared buckets.
The Service Role Key Problem in Vibe-Coded Apps
The Supabase service role key is the most dangerous credential in your project. It bypasses every RLS policy, every row permission, and every storage access check. In a correctly configured app, it only exists in server-side code that never reaches the browser. In a vibe-coded app that was scaffolded quickly, it frequently ends up in the client bundle. A Belsoft security audit of a vibe-coded app checks for this explicitly: we look at every Supabase client initialization point in the codebase and test whether Storage and database operations work from an unauthenticated browser session using the values present in the page source.
- →How it gets exposed: AI coding tools sometimes initialize a single Supabase client with both the anon key and the service role key, then use it for all operations — uploads, reads, database queries. The client bundle is sent to the browser and both keys are readable from DevTools. Any user of your app can extract the service role key and perform any database or storage operation on your project.
- →How to check: open your deployed app in Chrome, open DevTools, go to Sources, and use the search function to look across all loaded files for your Supabase project reference string or for the string service_role. If you find a JWT that is not your anon key, the service role key is in the client.
- →The fix: create two Supabase client instances — one for client-side use with the anon key (NEXT_PUBLIC_SUPABASE_ANON_KEY), and one for server-side use only with the service role key (SUPABASE_SERVICE_ROLE_KEY, without the NEXT_PUBLIC_ prefix). The server-side client belongs in Next.js Route Handlers, server components, and Edge Functions — never in component files or client utilities.
- →Authentication helpers handle this correctly: if you use the official Supabase Auth helpers for Next.js, the browser client uses the user's session JWT and the server client can use the service role key for administrative operations only. The helpers are designed around this split — using them correctly means the service role key stays server-side by default.
What to Test Before You Ship File Uploads
Before treating Supabase Storage as production-ready, run these verification steps. They cover the specific gaps we find most often when reviewing vibe-coded apps in a pre-launch security audit.
- →Create a second Supabase test account and try to read files uploaded by the first account by constructing the file path. If the read succeeds, your Storage RLS policy is wrong or missing.
- →Try to upload a file with a blocked MIME type — for example, upload an .html file to an image-only bucket. The upload should fail with a type error from the Storage API, not succeed silently.
- →Try to upload a file that exceeds your size limit. The upload should fail before the file is stored, returning a file size error from the API.
- →Open your deployed app in Chrome DevTools, go to Sources, and search all bundles for your Supabase project reference and the string service_role. If you find the service role key, it needs to be moved to server-only environment variables before launch.
- →Generate a signed URL server-side for a file, let it expire, and then try to request the URL again. The response should be an error, not the file contents. If you still receive the file, check cache-control settings on the object and any CDN layer in front of Storage.
- →Test cross-user signed URL generation: sign in as user B and attempt to call your signed URL generation endpoint with a file path that belongs to user A. Your server-side authorization check should block this request before it reaches Storage — not rely solely on RLS to handle it.
Frequently Asked Questions
Is Supabase Storage secure by default?
New buckets are created as private by default, which means every file operation requires a valid JWT and a matching RLS policy on storage.objects. However, private with no policies means no operations succeed at all — you must write the policies yourself. The common failure point is not a misconfigured default but explicit creation of a public bucket for convenience, or a vibe-coded app that ships with no RLS policies on storage.objects at all.
What is the difference between Supabase table RLS and Supabase Storage RLS?
Both use the same Postgres RLS engine, but they apply to different tables. Database table RLS applies to your application tables — users, posts, invoices, any table you create. Storage RLS applies to the storage.objects table, which is Supabase's internal metadata table that tracks uploaded files. Enabling RLS on your application tables does not protect files in Storage, and enabling Storage RLS does not protect database rows. Both require separate policy definitions.
Can you use Supabase Storage with Lovable or Bolt apps?
Yes, but inspect the generated code carefully before shipping. Lovable and Bolt scaffold Supabase Storage connections quickly, but they sometimes initialize the Supabase client with the service role key instead of the anon key, create public buckets for simplicity, or skip RLS policy creation entirely. Run the testing checklist in this post on any Lovable or Bolt app before you open file uploads to real users.
How do I make Supabase Storage files only accessible to the file owner?
Use a path prefix pattern: upload files to paths structured as {auth.uid()}/filename and write RLS policies that check auth.uid() = (storage.foldername(name))[1]::uuid. This enforces that the first folder segment of the path must match the authenticated user's ID. Test the isolation with a second account — a successful read from account B on account A's file means the policy has a gap.
Do Supabase signed URLs bypass row level security?
Authorization happens at URL generation time, not at request time. When you call createSignedUrl, Supabase validates the caller's JWT against your storage access controls. The resulting URL can then be used by anyone who holds it — without an active session — until it expires. The practical implication: generate signed URLs server-side after verifying the requesting user owns the file, so your server-side code is the authorization gate rather than relying on the client to pass a valid session at request time.
How Belsoft Helps Secure Your Supabase App
Most Supabase Storage vulnerabilities in vibe-coded apps share the same root cause: the AI tools scaffold a connection that works, and the developer ships before hardening the access model. Belsoft's security audit covers Storage explicitly — we review every bucket's public or private status, read the RLS policies on storage.objects, check for service role key exposure in the client bundle, test cross-user file isolation with real test accounts, and verify signed URL generation logic. Run DeployReady first to catch automated checks in seconds — it flags public bucket exposure, service key patterns in environment variables, and missing security headers. A Belsoft engineer then goes deeper: manual auth review, signed URL authorization gaps, path traversal edge cases, and anything the scanner cannot reach by running code.
If you have built with Lovable, Bolt, Cursor, v0, or any other AI tool and you are storing user files in Supabase Storage, the security review starts there. Learn more about our security audit service for vibe-coded apps, or book a call to walk through what your app's storage configuration needs before you open it to real users.
“A bucket that works is not the same as a bucket that is safe. The five-minute hardening session you skip is the one the breach report starts from.”
Written by
Marco Silva
Security Engineer, Belsoft Solutions
More from the blog
Ready to partner?
Let's talk about your company.
30 minutes. No pitch. We talk through how you run today and where AI and automation would help.
Book a free audit
