Skip to content
OverKnightsOverKnights home

AI-generated code security risks: a field guide for startups

The security weaknesses AI coding assistants introduce most often, why they happen, and a practical way to catch them before they reach production.

Mike Soertsz, Fractional CTOPublished 4 min read
Short answer

AI-generated code is not insecure by default, but assistants reliably reproduce a small set of weaknesses: hard-coded secrets, missing authorisation checks, admin keys in client code, unvalidated server input, unsigned webhooks and invented or typosquatted packages. They write the happy path quickly and skip the question of who is calling. The fix is a review layer that checks for these specific patterns on every change.

  • Most AI security bugs are omissions, not exotic exploits: a missing check, a missing verify step, a key in the wrong place.
  • The same dozen patterns cover the bulk of real findings, so a targeted checklist beats a generic review.
  • Run deterministic scanners first, then a focused review on what changed, and verify anything rated High or Critical.

Your team ships faster than it ever has. A feature that took a week now takes an afternoon, and most of the code was written by an assistant. The part nobody planned for is review: more code, written faster, read by fewer people.

This guide covers the security weaknesses AI coding tools introduce most often, why they happen, and how to catch them without slowing the team down. Every pattern below maps to an ID in our open AI code weaknesses checklist.

Why AI assistants produce predictable security bugs

Language models generate the most likely continuation of the code in front of them. That has three consequences for security.

  1. They optimise for code that runs. If a query fails because of a permission, the quickest working fix is a more powerful key. If a form submission fails validation, the quickest fix is less validation.
  2. They write the happy path. A prompt like "add an endpoint to update the plan" produces an endpoint that updates the plan. It rarely produces the check that the caller owns the organisation.
  3. They remember examples, not your version. Tutorials and README files are full of placeholder secrets, permissive CORS and simplified auth. Those shortcuts come back in generated code.

None of this is new to security people. What is new is the volume: one engineer with an assistant can add thousands of lines a week, and the same shortcut can appear in twenty files before anyone notices.

The weaknesses we see most often

IDWeaknessTypical shape in AI codeDefault severity
SEC-01Hard-coded secretsAn API key pasted into a config file to make a demo workCritical
SEC-02Missing authorisationA route or server action that never checks who is callingCritical
SEC-03Admin keys and no row-level securityA service role key in client code, tables without RLSCritical
SEC-05Unvalidated server inputA server action that trusts whatever the form sendsHigh
SEC-12Unsigned webhooksA payment webhook processed without verifying the signatureHigh
DEP-02Phantom or typosquatted packagesA dependency one letter off a popular libraryCritical
NX-01Secrets in public env varsA private key exposed through a NEXT_PUBLIC variableCritical

Missing authorisation is the big one

If you only check one thing, check this. Generated handlers usually authenticate (there is a session) but do not authorise (this session is allowed to touch this record). Here is the shape we see constantly:

"use server"
export async function setPlan(orgId: string, plan: string) {
  await db.org.update({ where: { id: orgId }, data: { plan } })
}

Anyone who can call this action can change any organisation's plan by sending a different orgId. The fix is one line of intent: load the session, confirm the user belongs to orgId with the right role, then update. Our guide to missing authorisation in server actions walks through the pattern in detail.

Secrets travel in two directions

SEC-01 covers secrets committed to the repository. NX-01 covers secrets shipped to every visitor's browser, which happens when an assistant fixes an "undefined on the client" error by adding a public prefix to a private variable. Both are cheap to detect with a secret scanner and a rule on environment variable names.

Packages that should not exist

Assistants sometimes suggest package names that were never published, or that resemble popular libraries. Attackers register those names. A lockfile review on every change, plus a check that each new dependency exists, has real usage and is spelled correctly, closes the gap. See slopsquatting and hallucinated packages.

How to catch these issues without slowing down

You do not need a security team to cover this. You need three layers that run on every change.

  1. Deterministic scanners. Secret scanning, dependency scanning and a static analysis rule set run in CI or nightly. They are fast, cheap and catch the obvious cases.
  2. A focused review of the diff. Someone, or something, reads what changed against a short list of AI-specific weaknesses: authorisation, validation, keys, webhooks, packages, placeholder logic.
  3. Verification before escalation. Every High or Critical finding gets a second look with the surrounding code, so the team only sees real problems. Noise is what kills review programmes.

This is the structure we run every night for clients, and it is the structure we recommend for teams that want to do it themselves. The AI code review checklist turns it into a repeatable routine.

What to put in your AI tool instructions

Most assistants accept project rules. A few lines prevent a surprising share of findings:

  • Every server action and API route must check that the caller is allowed to act on the specific record.
  • Validate all server input with a schema. Never trust types from the client.
  • Never use admin or service role keys in code that runs in the browser.
  • Verify webhook signatures before reading the payload.
  • Do not add a dependency without confirming it exists and is the intended package.

Rules reduce the rate of new issues. They do not remove the need to check, because assistants follow rules most of the time, not all of the time.

Where to start this week

  • Run a secret scanner across the full history of your main repositories.
  • List every route handler and server action and confirm each one authorises the caller.
  • Check that every table with user data has row-level security or an equivalent server-side check.
  • Add signature verification to every webhook handler.
  • Review dependencies added in the last three months.

If you want a second pair of eyes, we run a free sample on any public repository and send back three verified findings with fix prompts.

Frequently asked questions

Is code written by AI less secure than code written by people?

It fails differently. Assistants rarely invent a new class of bug, but they repeat common shortcuts at high volume and with high confidence, which means the same weakness can spread across a codebase in days.

Which AI coding tools does this apply to?

All of them. The patterns come from how language models generate code, so they appear in output from Cursor, Claude Code, GitHub Copilot and similar tools.

Do static analysis tools catch these issues?

Some. Secret scanners and dependency scanners catch SEC-01 and known CVEs well. Missing authorisation, placeholder logic and invented APIs need context, which is why a review pass on the diff is still needed.

OverKnights

Want to know what your repo would show?

Send one public repo. We reply with three verified findings and the prompts to fix them. No call needed.