Skip to content

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

RiskWhat it looks likeQuick checkWhen to fix
Secrets in client codeA paid API key or database secret in the browser bundle or git historySearch the built JavaScript and the git log for key prefixesThis week
Missing authorization checksThe UI hides a button, but the API serves any signed-in userReplay a request with another account's record IDThis week
Missing input validationThe server trusts whatever the form sendsSend the request with curl and add a field the form doesn't haveThis week
No observabilityYou learn about errors from customer emailsBreak something in staging and see what records itThis month
No testsEvery change puts signup, billing, or permissions at riskCount the tests that run in CI on a pull requestThis month
No migrations disciplineThe schema was changed in a dashboard or with db pushRebuild the schema from the repository and compare it with productionThis month
Unbounded queriesList pages fetch every row and slow down as data growsLook for a limit and pagination on every list endpointBefore usage grows
Dependency sprawlSeveral packages for one job, plus unused or abandoned onesRun a vulnerability audit and an unused-dependency checkBefore usage grows
What breaks in AI-built apps, how to check it, and when to fix it

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.

Search the build output, then list every commit that added or removed a matching line. Next.js writes client code to .next/static and Vite to dist, so keep the folder you have and add the prefix of every provider you use.bash
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.

On Supabase with default grants, every table this returns is open through the auto-generated API to anyone holding the public key.sql
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.

Scope each lookup to the signed-in user's organization, and answer 404 so the response never confirms that another customer's record exists.ts
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.

A strict schema rejects a request that adds role or any other field the endpoint doesn't expect.ts
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.

Keyset pagination reads one page at a time from the index, however large the table grows.sql
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.

  1. 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.
  2. 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.
  3. 03Validate input at every boundaryAdd schemas to request bodies, query parameters, webhooks, and uploads.
  4. 04Turn on error tracking and alertsIt is cheap to add, and it shows whether the first three fixes broke anything.
  5. 05Pin the critical paths with tests in CIFive to ten tests on the paths that make or lose money, running on every pull request.
  6. 06Put the schema under migrationsCapture the current production schema as a baseline migration, then restore a backup once to prove it works.
  7. 07Bound queries and add indexesStart with the endpoints your largest customers call most.
  8. 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.

FAQ

Common questions

Short answers to what readers ask next about this topic.

Yes. For a prototype that runs on test data and that only your team or a few trial users touch, speed matters more than any risk in this guide. The line moves when real customer data, payments, or third-party credentials enter the app, or when people outside your team can sign up. From that point, secrets, authorization, and input validation stop being optional.

Partly. A model asked to review a diff for security catches obvious issues such as a hardcoded key, which makes it a useful first pass. It shares the blind spots it had while writing, though, and it doesn't know your access rules unless you state them. The 2026 arXiv study Understanding the (In)Security of Vibe-Coded Applications found that better prompting and agent setups reduced vulnerabilities without removing them, so pair a model's review with tests and a human reviewer.

A penetration test probes the running app from outside, and enterprise buyers sometimes ask for one. It finds exploitable issues but says little about missing tests, migrations, or monitoring. Run the checks in this guide first, starting with the bundle search for keys and the authorization replay, so a pen test spends its time on harder problems.

Pixelact software audits start from $2,500 as a fixed fee, confirmed in writing and paid 100 percent upfront, so the price doesn't grow if the review takes longer. A sample report made from one of our own products shows the format before you pay. If the audit leads to a build within 60 days, 50 percent of the audit fee is credited against that build.

It depends on the code. Rotating keys can take an afternoon. Adding server-side authorization depends on how many endpoints and tables exist and how tangled the data model is. The risk table in this guide puts secrets, authorization, and input validation in the first week, and error tracking, tests, and migrations in the first month.

They may. Enterprise buyers often send security questionnaires about access control, encryption, logging, backups, and how you manage dependencies, and technical due diligence before a funding round can include a look at the code. Closing the gaps in this guide first makes those answers short and honest, with evidence such as CI test runs and migration history to point to.

Monthly newsletter

Get the next article by email

One short email a month on scoping, security, AI features, and releases, with links to new articles and checklists. Every issue is also published on the site, and every email has an unsubscribe link.

By subscribing, you agree to get the Pixelact newsletter by email. Every email has an unsubscribe link. Read the privacy notice.

Start a project

Tell us what you're building.

Share a few details in a short form, or book a discovery call if you're not sure where to start.

On the discovery call

  1. 01What prompted this now, and where things stand
  2. 02What a good outcome looks like
  3. 03Whether we're a fit, and what a next step could be

45 minutes. No slides, and no long questionnaire.