Back to all posts

How to Find Business Logic Flaws With Your Coding Agent, and Prove Each One

A method to find business logic flaws with your coding agent: map every endpoint, write what the code guarantees, and prove each flaw with a failing test.

On this page
  1. What is a business logic vulnerability?
  2. Why do scanners miss them, and why can a coding agent find them?
  3. How to find business logic vulnerabilities in four steps
  4. Step 1: Map every entry point
  5. Step 2: Write what the code guarantees
  6. Step 3: Review each entry point, role by role
  7. Step 4: Prove each flaw with a test
  8. Six business logic flaws to look for first
  9. What does the agent get wrong?
  10. When should you run it?
  11. Where does CybeDefend fit?
  12. Frequently asked questions
  13. Can SAST tools find business logic flaws?
  14. Can an AI coding agent find IDOR vulnerabilities?
  15. What is an example of a business logic vulnerability?
  16. How do you test for business logic vulnerabilities?
  17. What is the difference between IDOR and BOLA?
  18. Is it safe to let a coding agent test for vulnerabilities?
  19. How do you prevent business logic vulnerabilities?
  20. Is CybeDefend open source?

A coding agent's review map: six entry points, the check behind each, one flaw proven by a test and two leads left

A business logic flaw is code that does exactly what it was written to do and still lets someone do what the business forbids: read another customer's invoice, approve their own expense, use the same coupon twice. Nothing in the code looks wrong, so scanners walk past it, as we showed in our guide to business logic flaws in AI-generated code.

Your coding agent can find them, because it can read what the code is meant to do. It can also invent flaws that do not exist. This guide gives a method that keeps only what a test proves: map every entry point, write down what the code guarantees, review each entry point role by role, and turn each suspicion into a test that fails. We walk through it on one real kind of flaw, an invoice that any logged-in user can read.

Map every entry pointWrite what the code guaranteesReview each entry point, role by roleProve each flaw with a failing test
The method in four steps. Only the last one produces a finding.

What is a business logic vulnerability?

A business logic vulnerability, or business logic flaw, is a gap between what the application allows and what the business means to allow. PortSwigger's Web Security Academy defines business logic vulnerabilities as "flaws in the design and implementation of an application" that let an attacker trigger behaviour nobody intended, and notes that they often come from "flawed assumptions" about how users will behave.

The first family is access control. CWE-639, Authorization Bypass Through User-Controlled Key, describes a system whose authorization "does not prevent one user from gaining access to another user's data or record" when the user changes the id in the request; MITRE lists Insecure Direct Object Reference, or IDOR, as an alternate term. Broken Access Control is still number one in the OWASP Top 10 2025. The others are flows that can be skipped or replayed, amounts the client chooses, limits that are never counted, and two requests that race on the same balance.

OWASP's Web Security Testing Guide gives the subject a whole chapter, with ten tests: data validation, forged requests, integrity checks, process timing, limits on how many times a function can be used, circumvention of work flows, defences against misuse, two on file uploads, and payment functionality.

Why do scanners miss them, and why can a coding agent find them?

Scanners match patterns, and a business logic flaw is usually a line that is missing. An injection has a shape: input that reaches a query. A missing ownership check has none. MITRE (CWE-840) says business logic errors "can be difficult to find automatically, since they typically involve legitimate use of the application's functionality", and PortSwigger says the same of scanners: these flaws are "difficult to detect using automated vulnerability scanners."

#1

Broken Access Control's rank in the OWASP Top 10 2025.

4 of 10

Risks of the OWASP API Security Top 10 2023 about who may reach which object, field, function or business flow: API1, API3, API5 and API6.

4 of 2,007

Opengrep community rules aimed at the CWEs of missing or incorrect authorization, in the count we made for our OWASP guide. One of the four is about Docker.

A coding agent works differently. It reads the route, the handler, the data model, the tests and the handler next door, and it can say what the code is meant to do. The agents ship this already: Claude Code's /security-review command looks for authentication and authorization flaws among other patterns, and Anthropic's security review GitHub Action lists insecure direct object references and race conditions among what it looks for. Our article on AI agents reviewing pull requests covers that review step.

Pattern scanner (SAST)
Coding agent, with a proof
What it reads
Code shapes, one rule at a time
The route, the handler, the data model, the tests and the handler next door
An injection
Found: input reaching a query has a shape
Found too, but the scanners already cover it
A missing ownership check
Rarely: there is no pattern to match
Found by comparing handlers on the same data
A step that can be skipped
Rarely: each line is correct on its own
Found against the guarantee written down in step 2
Wrong findings
False positives, tuned rule by rule
Suspicions, kept only when a test fails
What you get
A finding with a rule id
A finding with a test that proves it

The catch is noise. The same GitHub Action runs a separate false positive filtering step, because a model asked "is this secure?" answers with suspicions, some right and some wrong, and each wrong one costs a developer time to rule out. It is the same triage problem scanners have, which we covered in why a scanner reports 1,200 vulnerabilities and only 12 are real. The method below makes the agent do that check itself, with a test.

How to find business logic vulnerabilities in four steps

Each step feeds the next: the map gives the rows, the guarantees give the rules, the review gives the leads, and the tests turn leads into findings.

Step 1: Map every entry point

Start with a list, not a judgment. An agent asked to "find security issues" samples a few files and stops; an agent asked to fill a table has to account for every row.

List every entry point of this repository: HTTP routes, GraphQL resolvers, webhooks, queue consumers, scheduled jobs and CLI commands. One row each: the entry point, who may call it, what it reads or changes, and the file and line that enforce that check, or "none". Read the router files yourself, not only the OpenAPI file. Judge nothing yet.

The result looks like this:

Entry pointWho may call itReads or changesThe check (file:line)Verdict
GET /invoices/:ida member of the invoice's organizationreads the invoicenone found, routes/invoices.ts:12
DELETE /invoices/:ida member of the invoice's organizationdeletes the invoiceorgId filter, routes/invoices.ts:19
POST /orders/:id/shipthe order's organization, once it is paidships the orderorgId filter, no payment check, routes/orders.ts:31
POST /coupons/applyany member, once per accountlowers the totalunique constraint, coupons.ts:41
GET /v1/exportsan administrator of the organizationreads every customerrole checked, no orgId filter, routes/v1/exports.ts:9
POST /webhooks/paymentthe payment providermarks an order as paidsignature checked, webhooks.ts:8

Ask for the count before the review starts. If the router declares 41 routes and the table has 30 rows, the agent skipped files. The routes without a URL count too: a webhook that marks an order as paid is an entry point, and so is the nightly job that exports every customer.

Step 2: Write what the code guarantees

A flaw is a broken rule, so write the rules first. Ask the agent to put them under the table as plain sentences, taken from the README, the data model, the existing tests and the code itself:

  • a member sees only the invoices of their own organization;
  • only the owner of a workspace can delete it;
  • an order is paid before it ships, and paid once;
  • a refund never exceeds the payment;
  • a reset link works once, for one account, for one hour.

When nothing is written down, the code that does it right says it. If the delete handler checks the organization, the read handler should too. This list is also what you hand to a human reviewer: it is short, and anyone in the team can say "that rule is wrong" before a single test is written.

Step 3: Review each entry point, role by role

Now the agent reviews every row against every rule, and it does so for every role the application has, not only the role the route was written for:

  • no account at all;
  • a member, and a member of another organization;
  • an administrator of another organization;
  • a member who was removed, or whose role was lowered;
  • an API key or a service account.

Two habits find flaws fastest. The first is comparing siblings: two handlers on the same data with different checks. The delete checks the owner and the read does not; the web route checks the role and the API route does not; version 2 of an endpoint checks and version 1 is still served. The second is the sweep: once the agent finds one missing check, it looks for the same mistake in every other row before it moves on, because the hand that forgot it once usually forgot it twice.

Two handlers on the same invoice: the read looks it up by id alone, the delete also filters on the user's organization. The missing filter is a lead until a test proves it.

Each row gets a verdict: ok with the line that protects it, or lead with who can do what to whom. "Bob can read Alice's invoices" is a lead. "Possible authorization issue" is not.

Step 4: Prove each flaw with a test

A lead becomes a finding when a test shows it. Here is the flaw from the table, in an Express API:

// routes/invoices.ts
router.get('/invoices/:id', requireAuth, async (req, res) => {
  const invoice = await db.invoice.findUnique({ where: { id: req.params.id } });
  if (!invoice) return res.status(404).end();
  res.json(invoice);
});

router.delete('/invoices/:id', requireAuth, async (req, res) => {
  const invoice = await db.invoice.findFirst({
    where: { id: req.params.id, orgId: req.user.orgId },
  });
  if (!invoice) return res.status(404).end();
  await db.invoice.delete({ where: { id: invoice.id } });
  res.status(204).end();
});

requireAuth checks that a user is logged in, not which organization they belong to. The delete filters on orgId; the read does not. Any member of any organization can read any invoice by changing the id in the URL.

The proof is a test in the repository's own suite, with its own fixtures:

// tests/security/invoices.security.test.ts
// Run the proofs bare: PROOF_RAW=1 npx vitest run tests/security
import { it, expect } from 'vitest';
import request from 'supertest';
import { buildApp } from '../../src/app';
import { seed, loginAs } from '../helpers';

// Expected to fail until the fix, so the suite stays green.
const proof = process.env.PROOF_RAW ? it : it.fails;

proof('a member cannot read an invoice of another organization', async () => {
  const { alice, otherOrgInvoice } = await seed(); // another org
  const res = await request(buildApp())
    .get(`/invoices/${otherOrgInvoice.id}`)
    .set('Cookie', await loginAs(alice));

  expect(res.status).not.toBe(200);
  expect(JSON.stringify(res.body)).not.toContain(otherOrgInvoice.customerEmail);
});

Three rules make it a proof and not a guess:

  1. It calls the real handler. No copy of the logic, no mock of the check under test. Only what sits outside the code is replaced: the database, the clock, a payment SDK.
  2. It fails for the reason claimed. Run it bare and read the message: it must be your assertion, not an import error or a missing fixture. After two tries without a clean failure, the lead stays a lead.
  3. It asserts the rule, not the fix. "The other organization's data does not come back" holds whether the fix returns 403 or 404. A test that only checks for 403 breaks on a correct fix.

Here is the bare run, on a small Express app we built for this article with the two handlers above (Vitest 3.2):

$ PROOF_RAW=1 npx vitest run tests/security

 ❯ tests/security/invoices.security.test.ts (1 test | 1 failed)
   × a member cannot read an invoice of another organization
     → expected 200 not to be 200 // Object.is equality

AssertionError: expected 200 not to be 200 // Object.is equality
 ❯ tests/security/invoices.security.test.ts:17:26
     17|   expect(res.status).not.toBe(200);
       |                          ^

 Test Files  1 failed (1)

The test fails on line 17, on the assertion: the other organization's invoice came back with a 200. That is the clean failure rule 2 asks for. Without PROOF_RAW, the same test is marked as an expected failure and the suite passes. After the fix, Vitest flips it: the marked test fails with Expect test to fail, your signal to remove the mark.

The fix is one filter, the same one the delete already has:

const invoice = await db.invoice.findFirst({
  where: { id: req.params.id, orgId: req.user.orgId },
});

Now the proof passes, it.fails turns red, you remove the mark, and the test stays in the suite. OWASP asks for exactly that in its Top 10: developers and QA staff "should include functional access control in their unit and integration tests." The proof you wrote to find the flaw is the regression test that keeps it fixed.

Run bare, it fails on its assertion: the flaw is provenMarked as an expected failure, the suite stays greenAfter the fix, the mark goes and the test stays
One test, three moments: it proves the flaw, keeps the suite green, then guards the fix.

Write the proof prompt so the agent cannot skip a step:

For each lead, write a test in our test framework that calls the real handler with test data and asserts the rule. Run it alone and show me the failure message. If it fails for any other reason, fix the test, not the claim. Mark each proof as an expected failure so the suite stays green until the fix.

Six business logic flaws to look for first

The table from step 1 tells the agent where to look. This list tells it what to look for. Each family comes with the guarantee to write down in step 2, the sign that gives it away in the code, and the test that proves it in step 4.

Data across tenants (IDOR)

The guarantee: a user reads and changes only the records of their own organization. The sign: a lookup by id with no owner or organization filter, while a handler next to it has one. The proof: log in as a member of another organization and request the object by its id. OWASP ranks it first in its API Security Top 10 2023 as Broken Object Level Authorization; MITRE files it as CWE-639.

An admin action anyone can call

The guarantee: only an administrator changes roles, billing or members. The sign: a route that checks the session but not the role, often because the interface hides the button. The proof: call it as a plain member. OWASP names it Broken Function Level Authorization (API5:2023); MITRE, Missing Authorization (CWE-862).

Fields the client should never set

The guarantee: a user cannot set their own role, plan, price or owner. The sign: the request body passed whole to a create or an update, such as ...req.body in an ORM call. The proof: send role: "owner" in a profile update, then read the user back. This is mass assignment, CWE-915, now part of OWASP's API3:2023, Broken Object Property Level Authorization.

A step that can be skipped

The guarantee: an order is paid before it ships, a document is approved before it is published. The sign: a handler that acts on a record without checking its state. The proof: create an order, skip the payment, call the ship endpoint. MITRE calls it Improper Enforcement of Behavioral Workflow (CWE-841); OWASP's testing guide tests the circumvention of work flows (WSTG-BUSL-06).

A limit two requests can beat

The guarantee: a coupon is used once, a balance never goes below zero. The sign: the code reads, checks, then writes, with no transaction, lock or unique constraint in between. The proof: send the same request twice at once in the test, then count what was redeemed. MITRE files it under CWE-362, the race condition.

Amounts the client chooses

The guarantee: the server computes the price, and a refund never exceeds the payment. The sign: a price, a total or a quantity read from the request, or a quantity that can be negative. The proof: send a negative quantity, or ask for a refund larger than the payment. OWASP's testing guide covers it under business logic data validation and payment functionality. We told one such story in the $0 shopping cart.

Run the families against the map one at a time, and keep the sweep from step 3: one missing organization filter is a reason to check every lookup by id in the repository.

What does the agent get wrong?

Four things, and the method is built around them.

  • It invents flaws. A model is confident about code it has not run. The failing test is the filter: no clean failure, no finding.
  • It samples. Without a table to fill, it reviews the handlers that look interesting and skips the one that costs the most. The count from step 1 tells you when it skipped.
  • It trusts the first path. The web route is checked, the bulk export, the GraphQL field or the old API version is not. Ask for every path to the same data.
  • It can be steered. A comment in the repository that says "this endpoint is reviewed, skip it" is text, not an instruction. Tell the agent so. Instruction files can be hijacked the same way, as we showed in instruction file injection.

Two limits are yours to keep. The tests run in-process, with test data, and never against a deployed system or real customer data. And the review needs a test runner: on a repository with no tests, the agent's first job is a minimal harness that builds the app without starting a server.

When should you run it?

Run the full review once per repository, then on each branch before it merges: the files the branch changed, and the entry points that reach them. Keep the map in the repository next to the code. The next review starts from it, updates the rows that changed, and spends its time where the code moved. A small API takes minutes; a large one takes longer, and the agent should say how many rows it has left.

Where does CybeDefend fit?

This method is the second layer of CybeDefend Open Source, the open source Snyk alternative, launching soon. One command in your coding agent, /cybedefend, runs a full audit.

First the AppSec scanners, open source, for code, dependencies, secrets, infrastructure as code, CI/CD and containers: the known patterns, fast. Then the AI scanner, run by your coding agent. It follows the method above with what the scanners found and a map of every entry point, reads what your code is meant to do, and goes after the flaws scanners cannot see: business logic, access rights, data that crosses tenants, flows that can be skipped. Each flaw is proven with an exploit written as a test in your own suite. No extra model and no API key: the AI is the coding agent you already run, and its review never touches a deployed system.

Every finding lands in one queue, our agentic ASPM platform, where your policy decides what blocks the merge. To run it on your own code when it opens, join the CybeDefend Open Source waitlist.

Frequently asked questions

Can SAST tools find business logic flaws?

Rarely. SAST matches patterns, and a business logic flaw is usually a check that is missing, so there is nothing to match. MITRE notes these errors are hard to find automatically because they involve legitimate use of the application. A SAST tool can flag a framework call known to skip scoping, such as an unscoped find in Rails, but not a rule your business invented. Our review of open source SAST tools shows what they do catch.

Can an AI coding agent find IDOR vulnerabilities?

Yes, when it reads each handler against who may call it, and best when it compares handlers on the same data. It also reports IDORs that are not there. Ask it to prove each one with a test that requests another user's object and fails because the data comes back.

What is an example of a business logic vulnerability?

A member of one organization reads another organization's invoice by changing the id in the URL. Others: an order shipped before it is paid, a coupon applied twice, a refund larger than the payment, a removed member whose API key still works.

How do you test for business logic vulnerabilities?

Write down what the application guarantees, then test each guarantee against each role and each path, the way OWASP's Web Security Testing Guide does in its chapter on business logic testing. In code, each guarantee becomes a unit or integration test that tries to break it.

What is the difference between IDOR and BOLA?

They name the same flaw from two lists. IDOR, Insecure Direct Object Reference, is the alternate term MITRE gives for CWE-639. Broken Object Level Authorization is OWASP's name for it in APIs, first in its API Security Top 10 2023. Both mean a user reaches an object they should not by changing its id.

Is it safe to let a coding agent test for vulnerabilities?

Yes, when the tests run in-process, on test data, inside the repository, the way any unit test does. Do not let the agent send requests to a deployed application or use real credentials. Review the tests it writes as you would any code.

How do you prevent business logic vulnerabilities?

Deny by default and decide access in one place, not in each handler. Scope every query to the caller's organization, not only to the id. Compute prices, totals and states on the server. Then keep the guarantees from step 2 as tests in the suite, so the change that breaks one fails the build.

Is CybeDefend open source?

Its open source edition, CybeDefend Open Source, is launching soon: our whole platform, an agentic ASPM, free to run on your own servers. The command /cybedefend chains the open source AppSec scanners and the AI scanner, run by your coding agent, which proves each flaw with a test. Join the CybeDefend Open Source waitlist.