Outsider Broke AI Agent Security Pattern in Three Ways
A stranger rebuilt a published AI agent security pattern, passed its tests, then found three ways to leak one customer's data as another — including a path where the agent changed its own permissions.
By Daniel Okafor
5 min read

What's News
- A reader found three data-leak paths in the setup the same day the article was published.
- Row-level security was enabled on orders but never on products, exposing both customers' catalogues.
- A single Postgres query could change the session's customer value and disable the query timeout.
- The fix for the pooled-connection crash was one function call.
- OWASP labels the underlying risk excessive agency: permissions beyond the job's requirements.
A developer who had never met the authors broke their published AI agent security setup in three separate ways on the same day the article went live. He rebuilt the pattern from scratch, seeded it with two test customers, ran the authors' own tests, and then read one customer's data while logged in as another.
The authors reproduced all three bugs before changing anything, fixed the article, and credited the reader at the top. The pattern in question is one the authors say they recommend on almost every AI project they take on: give the agent its own database role, grant only needed columns, pin queries to one customer with row-level security, and write a leak test.
The bugs matter less than what they reveal about how most teams, including the authors', approach AI agent security today.
What was the first gap?
The design granted the AI role read access to two tables, orders and products. The authors switched on row-level security for orders only. They never switched it on for products.
Every test they wrote targeted orders, because orders were what they worried about. The reader asked the agent's "low stock" tool a question and got back both customers' product catalogues.
The authors say the lesson is not "remember every table," because people don't remember every table. The real lesson: a test written from memory only covers what you remembered. The reader's fix was better than theirs. His test asks the database for every table the AI role can read and fails if any table lacks a policy. It depends on no one's memory and keeps working when a new table is added next year by someone who never read the article.
How could the agent change its own permissions?
The design told the database which customer a request belonged to through a session value, which the application set and the model never touched. That held as long as the model could only call fixed queries.
But the article had also floated letting the model write its own SQL. The reader showed what that would mean. Postgres lets any role call a built-in configuration function that changes session settings. A single query could change the customer value halfway through and read another customer's orders. The same function could switch off the timeout the authors had set to protect against runaway queries.
This is the pattern that worries the authors most about the current wave of agent tooling. Every capability given to an agent becomes a capability an attacker can try to use through it. Security guidance for the Model Context Protocol makes the same point at the protocol level: tools should get the narrowest permissions their task needs. The authors now tell clients that named, fixed queries are the default, and model-written SQL only runs after passing a strict allowlist that checks what the statement actually does.
Why did "fail closed" fail differently in production?
The policy was designed to return nothing rather than everything when a request forgot to specify a customer. The authors tested it. It worked — on a fresh database connection.
In production, applications reuse connections through a pool. On a connection that had already served a request, the "missing" value came back as an empty string rather than as nothing at all. The query did not leak data, but it crashed instead of returning an empty result, and whether it crashed depended on which connection the pool handed out. The fix was one function call. Finding it took an outsider who did not share the authors' assumptions about how the code would be used.
What changed in how the team works?
The authors list four process changes:
- Inventory beats memory. Wherever a security rule must cover "every table," "every tool" or "every endpoint," they now test by asking the system for its own list rather than writing the list by hand.
- Every capability an agent has is assumed to be used against it. Before an agent gets a tool, they ask what the worst person who can talk to the agent could do with it. If the answer includes changing its own permissions, the tool does not ship.
- Guardrails get tested in real conditions: pooled connections, concurrent requests, retries, real data volumes. A guardrail that only holds on a developer's laptop is not one.
- They want outsiders to look. Getting broken in public, by someone friendly, within a day, was the best available outcome; the alternative was finding these gaps in a client's production system.
Why does this matter beyond one article?
OWASP's list of top risks for LLM applications names the underlying problem: excessive agency, meaning an AI system granted more permissions than its job requires. The authors note that much of the AI agent conversation concerns capability — which model, which framework, how many tools — while far less concerns the permissions, policies and tests that decide what happens when the model does something nobody intended. That layer, they argue, is mostly ordinary software engineering: least privilege, tests that don't rely on memory, and review by people who didn't write the code. AI agents have not changed those rules; they have raised the cost of skipping them, because the thing on the other side of the permissions now tries every door it is given, as often as it is asked. The walkthrough was wrong in three places and right in its main claim: access control for AI agents belongs in the systems the agent touches, not in the prompt.
Source: unite.ai
More from Daniel Okafor
Show full bio
Correspondent covering money, funding and market shifts around entrepreneurship, startups and venture funding at Business Bearings.
2,722 articles