Vibe coded app security comes down to one gap: AI coding tools help you ship a working product fast, but they optimize for "it works", not "it is safe". The code runs and the demo looks right, but nothing tells you that any signed-in user can read every other user's records. This is the pre-launch security checklist I use to find and fix those gaps before real users and real data arrive, usually without a rewrite.
On this page
Why vibe-coded apps ship with security gaps
An AI coding assistant is very good at the question you asked: make this page load the user's invoices. It is less reliable on the questions you did not ask: what happens when someone changes the ID in the URL, or calls the API without logging in? Code that runs is not the same as code that has been threat-modelled.
The same patterns turn up again and again:
- Missing ownership checks. A route loads a record by the ID it was given and never asks whether the caller owns it.
- Over-trusting the client. User IDs, roles, prices and plan limits are read from the request body, because that made the feature work in the browser.
- Secrets in the wrong place. A key gets a
NEXT_PUBLIC_prefix to fix an "undefined" error, and now it ships to every visitor. - Defaults left open. Tables without row level security, public storage buckets, debug routes and permissive settings that were meant to be temporary.
None of this means the tools are bad. The prompt said "make it work", and the tool did. Security is a separate pass.
Supabase comes up often below because its security depends on policies you write yourself. If you are still choosing a backend, my Supabase vs Firebase comparison covers how each handles access rules.
Vibe coded app security checklist
Work through these in order. The first four cover most of the serious risk in a typical Next.js and Supabase app. Each item says what to check, how to check it, and how to fix it.
1. Row level security on every table
- What to check: every table in an exposed schema has RLS enabled, with policies that limit rows to their owner or tenant rather than letting any signed-in user read or write any row.
- How to check it: check the Supabase security advisor for tables without RLS. Then, with two test accounts and only the public anon key, try to select, update and delete user B's rows as user A.
- How to fix it: enable RLS, write one policy per operation that compares
auth.uid()or a membership lookup with the row, and addWITH CHECKto inserts and updates. The full list of Supabase row level security mistakes is in Supabase RLS mistakes that leak customer data.
2. IDOR: ownership checks in API routes
- What to check: an IDOR vulnerability (insecure direct object reference) is an ID in a URL or request body that is trusted without checking the caller owns the record.
/api/invoices/123returns invoice 123 to whoever asks. - How to check it: sign in as user A, copy a request from the browser's network tab, swap in an ID that belongs to user B, and replay it. Do the same for updates and deletes, not only reads.
- How to fix it: take the user from the session, never from the request, and filter by both the record ID and the owner or tenant. This matters most when a route uses a service-role client, because RLS is not there to catch a missing filter.
Illustrative example, not production code. A route handler that checks the session, then checks the record belongs to the caller:
// Illustrative example only, not production code.
// app/api/invoices/[id]/route.ts
import { NextResponse } from "next/server";
import { createClient } from "@/lib/supabase/server"; // server client built from the request cookies
export async function GET(_req: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const supabase = await createClient();
// 1. No session, no data.
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
// 2. The ID came from the URL, so check the record belongs to the caller.
const { data: invoice } = await supabase
.from("invoices")
.select("id, amount, status")
.eq("id", id)
.eq("user_id", user.id)
.maybeSingle();
// 3. Same answer for "not yours" and "does not exist".
if (!invoice) return NextResponse.json({ error: "Not found" }, { status: 404 });
return NextResponse.json(invoice);
}And the matching policy, so the database refuses the same request even if a route forgets the filter:
-- Illustrative example only. The database enforces the same rule.
alter table invoices enable row level security;
create policy "Users read their own invoices"
on invoices for select
to authenticated
using ( (select auth.uid()) = user_id );3. Unauthenticated endpoints
- What to check: routes, server actions and edge functions that respond without a session. Server actions are easy to miss: they are public POST endpoints, even when the button that calls them sits behind a login screen.
- How to check it: list every route under
app/api, every"use server"function and every edge function, call each with no cookies, and note anything that returns data or changes state. - How to fix it: check the session at the top of every handler, not only in middleware, and fail closed. Public endpoints, such as a contact form, get validation and rate limits instead.
4. Secrets and keys
- What to check: service-role or admin keys, payment secret keys and AI provider keys must never reach the browser or the repository. Anything in a
NEXT_PUBLIC_variable is bundled into client JavaScript and readable by every visitor. - How to check it: search the code and git history for key names, review every
NEXT_PUBLIC_variable, and search the loaded JavaScript in dev tools. The Supabase anon key is meant to be public; the service-role key is not. - How to fix it: move secrets to server-only environment variables, use them only in server code, and rotate any key that was ever committed or shipped to the client. Deleting it from the code does not delete it from git history.
5. Webhooks
- What to check: payment and messaging webhooks verify the provider's signature before doing anything, and handle the same event arriving twice.
- How to check it: open each webhook route and look for signature verification against the raw request body. Then ask: if I post a fake "payment succeeded" event to this URL, does someone get a paid plan?
- How to fix it: verify the signature with the provider's SDK or documented method, reject anything that fails, and store processed event IDs so a retried event is not applied twice.
6. Input validation and rate limiting
- What to check: forms, sign-in, password reset and AI endpoints that accept whatever they are sent, as often as it is sent. AI endpoints are the expensive case, because every call costs money.
- How to check it: send oversized, malformed and unexpected values to each endpoint, then send the same request in a fast loop. See whether anything stops you.
- How to fix it: validate every input on the server with a schema library such as Zod, cap lengths and sizes, rate limit auth, forms and AI routes, and set a spending cap with your AI provider.
7. Storage buckets and file uploads
- What to check: buckets holding private files that are public, upload policies that let any signed-in user write anywhere, and uploads that accept any file type or size.
- How to check it: check each bucket's public setting and its policies on
storage.objects, try opening another user's file by changing its path, and try uploading an HTML or SVG file. - How to fix it: make private buckets private and serve files through signed URLs, scope policies to a per-user or per-tenant folder, and restrict file types and sizes on the server, not only in the file picker.
8. AI features
- What to check: prompt injection from user content (a note that says "ignore your instructions"), tools that can do more than the signed-in user is allowed to, and personal data written to logs.
- How to check it: list every tool the model can call and what it can reach, plant an instruction in a record the assistant will read, and check what your logs store.
- How to fix it: run tools as the signed-in user, take user and workspace IDs from the session rather than the model, confirm before any write, and redact sensitive fields from logs. The full pattern is in how to build an AI assistant inside your SaaS product.
9. Auth flows
- What to check: reset links that never expire, unverified emails with full access, sessions that survive a password change, and admin pages protected only by not being linked.
- How to check it: walk through sign-up, reset and sign-out as a real user. Then visit admin URLs as a normal user and call the admin APIs directly.
- How to fix it: use your auth provider's built-in flows rather than custom ones, require verification where it matters, and check the admin role on the server for every admin page and route. Read roles from a table or server-set claims the user cannot edit.
10. Dependencies and environment
- What to check: leftover debug and test routes, verbose errors that return stack traces or SQL, source maps published to production, and packages nobody uses.
- How to check it: search for routes named test, debug or seed. Trigger an error and read what the response contains. Check whether
.mapfiles load in production, and runnpm audit. - How to fix it: delete what you do not need, return generic errors and log details on the server, keep production browser source maps off (the Next.js default), and remove unused dependencies.
A 30-minute self-audit you can run today
If you want to know how to audit an AI-generated app before launch and have half an hour, start here. You need the codebase, two test accounts in different organisations, and a private browser window.
- List every route (5 minutes). API routes, server actions, edge functions and webhooks.
- Call each without a session (5 minutes). Anything that returns data or changes state is a finding.
- Call each as the wrong user (10 minutes). User A requests user B's records: reads, updates and deletes.
- Search for secrets (3 minutes). Key names in the repo, and every
NEXT_PUBLIC_variable. - Review policies (5 minutes). RLS on every table, and no policy open to every signed-in user.
- Check webhooks (2 minutes). Each one verifies a signature before doing anything else.
Copy this vibe coding security checklist into your notes or issue tracker and tick it off:
PRE-LAUNCH SECURITY SELF-AUDIT
[ ] Route list: API routes, server actions, edge functions, webhooks
[ ] Every route called with no session: no data back, nothing changed
[ ] Every route called as user A with user B's IDs: 404 or 403
[ ] Updates and deletes tested across accounts, not only reads
[ ] RLS enabled on every table in exposed schemas
[ ] No policy gives private data to any signed-in user
[ ] No service-role or secret key in client code or NEXT_PUBLIC_ vars
[ ] Repo and git history searched for committed keys
[ ] Webhooks verify signatures and ignore duplicate events
[ ] Rate limits on sign-in, password reset, forms and AI endpoints
[ ] Private buckets are private; uploads limited by type and size
[ ] No debug routes, stack traces or production source mapsAnything you cannot tick is a finding. Fix the cross-account and unauthenticated ones first; they expose other people's data.
What I found auditing a real multi-tenant SaaS
I ran this kind of audit on LeadsMind, a production multi-tenant CRM, LMS and marketing platform. I audited 157 API routes, closed IDOR vulnerabilities, hardened row level security and removed unauthenticated endpoints.
The platform, the audit and the rest of the build are covered in the LeadsMind CRM and LMS case study.
When to get a second pair of eyes
A self-audit is enough for plenty of early products: a single-user tool, an internal prototype, or a beta with a few friendly users and no sensitive data. Run the 30-minute routine, fix what it finds, and launch.
A review is worth it when the cost of a mistake lands on someone else: you store other people's personal data, you take payments, several businesses share one database, or AI features can read or change data through tools. A good security audit for AI-generated code gives you a ranked list of specific gaps with fixes, not advice to start again, and getting vibe coded app security right then is far cheaper than explaining a leak.
I review apps like this through my Supabase security and RLS audits and as a full-stack developer for Next.js products; features with tool access fall under my work as an AI developer for SaaS products. If you have not built yet, security from the first milestone is part of my SaaS MVP development work, and what a SaaS MVP costs to build shows where it fits in the budget.
FAQ
Is vibe coded software secure?
It can be, but not by default. AI coding tools write code that works for the scenario you described and often skip checks for the ones you did not, such as another user requesting your data.
What security problems do AI-built apps usually have?
Missing ownership checks in API routes (IDOR), tables without row level security or with policies that allow any signed-in user, endpoints that respond without a session, secret keys exposed to the browser, and webhooks that do not verify signatures.
How long does a security audit of an AI-generated app take?
It depends on the size of the app: the number of routes, tables, integrations and AI features. A small app can be reviewed quickly; a multi-tenant platform takes longer.
Do I need to rewrite my vibe-coded app to make it secure?
Usually not. Most gaps are specific: a missing check in one route, a policy that is too broad, a key in the wrong place. A rewrite only makes sense if the data model itself cannot separate users or tenants.
Is Supabase secure by default?
Supabase is secure when row level security is enabled and the policies are correct. The browser talks to the database through Supabase's API, so a table without RLS, or with a policy that is too broad, is reachable by anyone with your public anon key. To secure a Supabase app, start with the policies.
Can I hire you to review my app before launch?
Yes. I review Next.js and Supabase apps for the issues in this checklist, then fix them or hand you a written list of findings. Use the Hire me button or book a free 30-minute call.