All insights
ArticlePublished 6 min read

Silent vulnerabilities: how AI-generated code breaks access control, and how to protect your business data

AI-generated code can work perfectly and still expose your data. Five silent pitfalls to look for, how to fix them with OWASP's guidance, a review checklist, and how the Alphaise harness protects business data in layers.

AI coding assistants can generate server actions, API routes and full-stack components in seconds. Building features has never been faster. But code that compiles and works is not automatically secure.

Endor Labs tracks this in its public Agent Security League, which tests AI coding agents on 200 real-world tasks. When we checked in November 2026, the highest security score of any agent was 36.9%, while the highest functional score was 91.6%. In other words, the code usually works far more often than it is safe.

The risk this article focuses on is one that working code hides especially well. Broken access control is number one in the OWASP Top 10:2025, and OWASP reports that 100% of the applications tested had some form of it. AI tools are often good at adding a login screen, but authorization is harder: not who you are, but what you are allowed to touch.

Five silent pitfalls in AI-generated code

These examples are common in full-stack frameworks such as Next.js, but the same mistakes can appear in any stack. None of them breaks a feature, which is why they survive a quick test.

1. Checking the login, but not who owns the record

The mistake: an endpoint verifies that a user is logged in, then updates whichever record ID it receives. If that ID comes from a hidden form field, anyone logged in can change it in the browser's developer tools and edit someone else's data. This is known as an insecure direct object reference (IDOR), and it maps to CWE-639 and CWE-566.

The fix: always scope the query by both the record and the authenticated user. OWASP's guidance is that access controls should enforce record ownership.

// Risky: any logged-in user can update any record
await db.todo.update({ where: { id: todoId }, data });

// Safer: the record must belong to the session user
const { count } = await db.todo.updateMany({
  where: { id: todoId, ownerId: session.userId },
  data,
});
if (count === 0) throw new Error("Not found");

2. Fetching data without checking authorization

The mistake: a component fetches sensitive data and assumes a parent page has already checked the user. When the component is later reused on a public page, that data is exposed to anyone. This maps to CWE-200 and breaks OWASP's rule: except for public resources, deny by default.

The fix: create a central data access layer where each function checks authorization itself. The check then travels with the data, wherever the function is called.

3. Different rules on different routes

The mistake: the same record can be changed through several paths, such as a server action and a REST route. A rule like “archived items cannot be edited” gets added to one and is missing from the other. This maps to CWE-862 and CWE-424.

The fix: put each rule in one policy function, such as isResourceEditable(user, resource), and call it from every path. OWASP's advice is to implement access control once and reuse it throughout the application.

4. Sending too much data to the browser

The mistake: a query returns a full database row and passes it to a client component, even though the page only shows a title. The screen looks fine, but anyone inspecting the network response can read the internal fields. This maps to CWE-201.

The fix: select only the columns you need, and map results to a data transfer object (DTO) that contains only what the client should see.

5. Validating the input, then saving the original

The mistake: a schema validator such as Zod checks the request, but the original object still goes to the database. An attacker can add fields such as role: "admin" or isPublic: true, and they get written. OWASP calls this mass assignment (CWE-915).

The fix: write only the validated output, which contains the fields your schema allows. As OWASP points out, this limits which fields can be written, but it does not replace the authorization check for the record itself.

const input = schema.parse(rawInput);

// Risky: extra fields in the request are written too
await db.post.update({ where, data: rawInput });

// Safer: only the validated fields are written
await db.post.update({ where, data: input });

A checklist for your next code review

Use these questions on any pull request that contains AI-generated code, especially anything that reads or changes customer or business data.

AreaWhat to askWhat good looks like
Record ownershipDoes every read and update check who owns the record?Queries are scoped by the session user
Data fetchingCan a query function run without an authorization check?All access goes through a data access layer
PolicyAre rules copied between routes and actions?One shared policy function for each rule
Data exposureDo full database rows reach the browser?Selected columns and DTOs only
Input handlingDoes the raw request reach the database?Only validated output is written

Why AI agents raise the stakes

The same boundaries matter even more once AI agents work inside your business systems. An agent acts on data quickly and repeatedly, often across several systems. If it has more access than its task needs, a single mistake or manipulated instruction can reach far more data than one person's error would.

So the principles above apply to agents too: deny by default, one place for the rules, only the data the task needs, and a record of what happened.

How the Alphaise platform protects business data

That is why we built a harness into the Alphaise platform. AI agents do not go straight to your data or your models. Each task passes through a set of layers, so the protection does not depend on any single check or on each agent being built perfectly.

The layers of the Alphaise harness: an agent's task passes through access, policy, human approval, models and audit, on top of a governed data layer hosted in the EU by default or on your own infrastructure.
  • Access: every agent has an owner and clear permissions, and gets the data and access its task needs.
  • Policy: guardrails and policies are checked in one place, not rebuilt for each agent.
  • Human approval: important steps, such as payments, approvals and anything sent to customers, wait for a person to review them.
  • Models: we choose the right model for each task based on quality, cost and where data may be processed, and you are not locked to one vendor.
  • Audit: an audit log and monitoring show what each agent did, and the compliance module links requirements from GDPR, ISO 27001, ISO 42001 and the EU AI Act to your processes.
  • Data: a governed data foundation keeps master data consistent, hosted in the EU by default or on your own infrastructure, with a data processing agreement signed before any project starts.

What to do next

A harness limits what an agent can do and shows you what it did. It does not make insecure application code secure, so you still need the reviews and tests above. The strongest position is both: secure code and controlled agents.

  1. Run the checklist on your most sensitive routes first, such as anything touching customer, finance or personal data.
  2. Add automated tests that try to read and change another user's records.
  3. List every AI agent and tool that can reach business data, with an owner and its permissions.
  4. Decide which actions always need a person's approval.

If you want help with any of this, book a discovery call and we will show you how the Alphaise platform fits your systems and data.

Sources

  1. OWASP Top 10:2025, A01 Broken Access ControlThe number one ranking, the 100% figure, the mapped CWEs, and the guidance on deny by default, record ownership and reuse
  2. OWASP Cheat Sheet Series: Mass AssignmentMass assignment (CWE-915), DTOs and allow-lists, and why they do not replace authorization
  3. Endor Labs: Agent Security LeagueFunctional and security scores for AI coding agents, as shown on the live leaderboard in November 2026

Let's simplify your business

Non-binding first call · No ROI, no invoice

Book a discovery call
en