Guide
Risks of AI-generated code in production, and what to fix first
Building fast with AI tools was a sensible trade. These are the eight places AI-built apps tend to break in production, how to check each one yourself, and which to fix first.
- Published
- Updated
- 10 min read
- By Dev Talan
Key takeaways
The short version. Each point is explained in full below.
- 01
Exposed secrets, authorization, and input validation come first, because anyone on the internet can exploit them today and a data leak can't be undone.
- 02
Error tracking, tests on a handful of critical paths, and schema changes under version control come next, because they make every later fix safe to ship.
- 03
Deleting a leaked key from the code doesn't take it back. Move the call behind a server route with a new key, then revoke the old one at the provider.
- 04
To test authorization, sign in as user A, replay a request with one of user B's record IDs, and see whether B's data comes back. On Supabase, also list the tables with row-level security off.
The main risks of AI-generated code in production are secrets shipped to the browser, authorization checked only in the UI, missing tests, unbounded queries, unvalidated input, dependency sprawl, no observability, and database changes made by hand. None of them shows up in a demo. Each has a quick check, and secrets and access control come first.
If you built the first version with Cursor, Lovable, Bolt, Replit, or Claude Code, you made a sensible trade. You put a working product in front of users before paying for an engineering team. This guide covers what comes next: eight failure classes that commonly show up in apps built fast, how to check each one in your own code, and the order to fix them in. The AI-built app risk checklist turns the same ground into yes-or-no checks you can work through with your team.
Is AI-generated code safe to run in production?
#AI-generated code is as safe as the review, tests, and limits around it. The code usually runs. The gaps sit in what a demo never exercises: a second customer, hostile input, a table with a million rows, and the morning after a bad deploy.
Published research on AI-generated code security points the same way. Veracode's 2025 GenAI Code Security Report tested more than 100 large language models on 80 coding tasks. When a task could be written securely or insecurely, the models chose the insecure way in 45 percent of cases. Security results stayed flat over time, and larger models did not do significantly better than smaller ones. A 2026 arXiv preprint, Understanding the (In)Security of Vibe-Coded Applications, audited 200 publicly deployed vibe-coded apps and found at least one vulnerability in 91 percent of them, concentrated in broken access control, injection, and authentication failures.
The gaps follow from how coding agents work. A coding agent works on the request in front of it, such as “add an invoices page”, and it can't see rules you never stated, such as which customer may read which invoice. It also repeats shortcuts common in tutorials, like calling a paid API straight from the browser.
What are the main risks of AI-generated code in production?
#These are the vibe coding risks that matter once real customers and real data arrive. The table ranks them by how quickly someone could hurt you with each one and whether the damage can be undone.
| Risk | What it looks like | Quick check | When to fix |
|---|---|---|---|
| Secrets in client code | A paid API key or database secret in the browser bundle or git history | Search the built JavaScript and the git log for key prefixes | This week |
| Missing authorization checks | The UI hides a button, but the API serves any signed-in user | Replay a request with another account's record ID | This week |
| Missing input validation | The server trusts whatever the form sends | Send the request with curl and add a field the form doesn't have | This week |
| No observability | You learn about errors from customer emails | Break something in staging and see what records it | This month |
| No tests | Every change puts signup, billing, or permissions at risk | Count the tests that run in CI on a pull request | This month |
| No migrations discipline | The schema was changed in a dashboard or with db push | Rebuild the schema from the repository and compare it with production | This month |
| Unbounded queries | List pages fetch every row and slow down as data grows | Look for a limit and pagination on every list endpoint | Before usage grows |
| Dependency sprawl | Several packages for one job, plus unused or abandoned ones | Run a vulnerability audit and an unused-dependency check | Before usage grows |
How do you check each risk in your own app?
#Most of the checks below need only repository access and a terminal. Run them against a staging copy where you can, and never against another customer's real data.
Secrets in client code
#When client code reads a variable prefixed NEXT_PUBLIC_ or VITE_, the build copies its value into the JavaScript every visitor downloads. A common shortcut is to put an OpenAI, Stripe, or database key there, because it makes the feature work on the first try. A key that was committed once also stays in git history after you delete the line.
npm run build
grep -rlE 'sk_live_[0-9A-Za-z]{10,}|sk-[0-9A-Za-z_-]{20,}|sb_secret_[0-9A-Za-z_-]{10,}' dist .next/static
git log --all --oneline -G 'sk_live_[0-9A-Za-z]{10,}|sk-[0-9A-Za-z_-]{20,}|sb_secret_[0-9A-Za-z_-]{10,}'Fix it in this order. Check the provider's usage logs first, and revoke the key at once if you see calls you didn't make. Otherwise, issue a new key that only the server holds, move the call behind a server route, and then revoke the old key, because deleting it from the code does not take it back. Set a spending limit with the provider while you are there. Our teardown of exposed API keys walks through the full rotation, the server route in code, and secret scanning in CI.
Missing authorization checks
#Authorization decides which records a signed-in user may read or change. In AI-built apps it often lives only in the interface: the admin button is hidden, but the endpoint behind it answers anyone with a session. Broken access control holds first place in the OWASP Top 10:2025.
To check, sign in as user A, copy a request from the browser's network panel, swap in the ID of a record that belongs to user B, and send it again. If B's data comes back, any signed-in user can read other customers' records through that endpoint. On Supabase, or any Postgres database behind an auto-generated API, also list the tables that have row-level security turned off.
select schemaname, tablename
from pg_tables
where schemaname = 'public'
and rowsecurity = false;A table with row-level security on can still be open if its policy reads using (true). On the server, scope every query by the organization or user in the session, never by an owner ID the client sends.
const invoice = await db.invoice.findFirst({
where: { id: params.invoiceId, organizationId: session.organizationId },
});
if (!invoice) {
return new Response('Not found', { status: 404 });
}Missing input validation
#When the form validates input, it is easy to assume the server does too. Anyone can skip the form and send the request with curl, adding fields like role or price, a negative quantity, or a 10 MB string. Validation keeps bad data out, but it does not make user text safe to render as HTML. That needs escaped output, and Veracode's report found the models failed to guard against cross-site scripting in 86 percent of cases.
Validate every request body on the server against a schema that lists the allowed fields and rejects the rest.
import { z } from 'zod';
const profileUpdate = z.strictObject({
name: z.string().trim().min(1).max(100),
timezone: z.string().max(64),
});
const result = profileUpdate.safeParse(await request.json());
if (!result.success) {
return Response.json({ error: 'Invalid input' }, { status: 400 });
}Apply the same rule to query parameters, webhooks, and uploads. Use parameterized queries or the ORM's query builder instead of string concatenation, and set size and type limits on every file upload.
No observability
#Observability is how you find out something broke before a customer tells you. Many first versions have console.log statements and nothing else, so a failed payment webhook or a broken signup can go unnoticed for days.
Ask one question: if signup broke an hour ago, how would you know? Prove the answer by throwing a deliberate error in staging and seeing whether anything records it and alerts someone.
Add error tracking such as Sentry, structured logs that carry a request ID, an uptime check, and an alert on failed webhooks. OpenTelemetry traces can wait until a request crosses several services. Keep secrets and personal data out of log lines, and treat logged user input as untrusted. Veracode found the models left log injection open in 88 percent of cases.
No tests
#Without tests, every AI-assisted change is a guess about what else it touched. Tests generated alongside the code can mislead too, because they can assert what the code does rather than what it should do.
Check whether a test suite exists, whether it runs in CI on every pull request, and whether any test signs in as one user and tries to read another user's data. Skip the coverage target. Write a handful of Playwright end-to-end tests on the paths that make or lose money, plus permission tests at the API:
- Sign up, verify the email address, and sign in.
- Complete the one action customers pay for.
- Check out, change plan, and process the payment webhook.
- User A cannot read or change user B's records.
- A regular user is refused at every admin-only endpoint.
No migrations discipline
#A migration is a versioned, reviewed change to the database schema that lives in the repository. In a first version, the schema is often changed by clicking in the Supabase dashboard or by running prisma db push, so production drifts away from anything in git and nobody can rebuild it.
To check, create an empty database, apply the repository's migrations, and diff pg_dump --schema-only of the result against production. Then ask when a backup was last restored.
Pick one migration tool, such as Prisma Migrate, Drizzle Kit, or the Supabase CLI. Review migrations like code and let CI apply them. Split breaking changes into expand and contract steps so a deploy can roll back. Our guide to safe releases and rollbacks covers the deploy side.
Unbounded queries
#An unbounded query fetches every matching row. With 50 rows in a demo it is instant. With 200,000 rows it can time out, load the database on every page view, and give anyone who calls the endpoint in a loop an easy way to slow the app for everyone.
Check every list endpoint for a limit and pagination, look for queries inside loops (the N+1 pattern), and run EXPLAIN ANALYZE on the slowest queries listed by pg_stat_statements. Then set a maximum page size, switch to keyset pagination, and add an index that matches the filter and the sort.
create index concurrently documents_org_created_idx
on documents (organization_id, created_at desc, id desc);
select id, title, created_at
from documents
where organization_id = $1
and (created_at, id) < ($2, $3)
order by created_at desc, id desc
limit 50;The performance and scalability checklist covers more of this ground.
Dependency sprawl
#AI tools add a package whenever one solves the task in front of them, so an app can end up with three date libraries, two HTTP clients, and packages nobody imports. Models sometimes suggest package names that don't exist, and an attacker can register such a name and wait for the install.
Check with npm audit --omit=dev for known vulnerabilities and npx knip for unused dependencies and files. For every package you don't recognize, confirm it exists on npm, links to a real repository, and still gets releases. Keep one library per job, commit the lockfile, and let Renovate or Dependabot keep updates small and regular.
What should you fix first?
#Fix what an outsider can exploit today and what can't be undone, then add the safety nets that make every later fix safe to ship. In practice the order looks like this.
- 01Rotate and move exposed secretsMove every call that used an exposed key to the server with a new key, revoke each key that reached the browser or git history, and set spending limits with each provider.
- 02Enforce authorization on the serverScope every read and write to the session, turn on row-level security wherever a public API reaches the database, and test both.
- 03Validate input at every boundaryAdd schemas to request bodies, query parameters, webhooks, and uploads.
- 04Turn on error tracking and alertsIt is cheap to add, and it shows whether the first three fixes broke anything.
- 05Pin the critical paths with tests in CIFive to ten tests on the paths that make or lose money, running on every pull request.
- 06Put the schema under migrationsCapture the current production schema as a baseline migration, then restore a backup once to prove it works.
- 07Bound queries and add indexesStart with the endpoints your largest customers call most.
- 08Prune dependenciesRemove unused packages, replace abandoned ones, and automate updates.
Hold off on the rewrite
A rewrite feels cleaner, but it pauses the product and repeats the same gaps unless the review habits change. Many AI-built apps can be stabilized in place. Our guide to rebuilding or refactoring an app covers how to tell which case you are in.
Should you stop building with AI coding tools?
#No. Keep the speed and add the review that production needs. We use AI tools to draft code, tests, and first-pass review comments in our own work, and an engineer reads every diff and decides what merges.
Two rules carry most of the weight. A person who knows the system reviews every change that touches authentication, money, personal data, or the schema. CI runs tests, a secret scanner, and a dependency audit on every pull request, and a failing check blocks the merge. Small pull requests keep that review honest. Our AI code review workflow describes one way to set it up.
When does an AI-built app need an audit or a rescue?
#An AI-built app needs an outside audit when the checks turn up more than your team can rank, and a rescue when releases already break something every week. Start with the AI-built app risk checklist this week. If the secrets and authorization checks pass, work down the rest of the list at your own pace.
Our guide to what a software audit covers shows the areas reviewed and what one finding in the report looks like. A software audit gives you about 3 to 5 days of review and a written report that ranks the risks and fixes, and a rescue starts with the same audit.