AI and agent security
Treat the model as an untrusted component that holds your credentials: draw the new trust boundary, decide what the agent may do without a person, and enforce it in code
Owoleaf's support agent is about to get a refund tool. A customer might write anything into the chat. Where does the security engineer put the control that decides whether a given refund is allowed?
An AI feature adds one question to every review you already run: what can this thing do, and who gets to tell it what to do? A model that only produces text for a person to read has a modest threat model. A model with tools, which read records, send messages or move money, has an attack surface that includes every piece of text it reads. This chapter is the security engineer’s side: the threat model, the choice of what the agent may do alone, and the controls that make the choice real.
It does not re-teach the attacks. Guardrails, safety and prompt injection explains why instructions in data get followed and why prompt wording cannot fix it, and Tool use and function calling shows how the model proposes and your code decides. Read both first; this chapter assumes them.
The model: a confused deputy with a keyboard
Norm Hardy named the confused deputy in 1988: a program that holds authority of its own is tricked by a caller into using it for the caller’s purposes, because nothing checks whose purpose it serves. An LLM agent is that program with a language interface. It holds the company’s credentials and reads text from the customer, from help articles, from earlier tickets and from tool results. Some of that text was written by people with no right to spend the company’s money, and the agent cannot reliably tell which.
Two consequences follow.
Model output is user input. Everything the model emits, a tool name, an argument, a sentence the interface will render, came from a process that attacker text influenced. Treat it as secure code review treats a request parameter: untrusted, and validated at the sink.
The trust boundary moves inside the process. In an agent, the operator’s instructions, the customer’s message and a retrieved article sit in one context window, and the component that decides cannot enforce a boundary between them. So you draw the line where the model’s proposal becomes an action: the tool dispatcher. The model’s side is untrusted advice; the dispatcher’s side is ordinary code with ordinary controls.
Ask of an agent the three questions from identity, access and secrets. Whose authority does it act with? What does that authority open? How long does it last? The agent is a service identity, and the best answers are the same: a narrow role per tool, short-lived credentials, no standing admin token, and an owner who can switch it off.
Drawing the system: the Owoleaf support agent
Take Owoleaf at 200 people, with 44 engineers in six teams. Its customer-facing support assistant answers in the customer’s language from help-centre articles it retrieves. Its instruction says never to ask for a PIN, password or OTP, to give the session ID for a late transfer, and to escalate to a human agent. Add the refund capability the business wants, and draw it as a data-flow diagram, the way threat modelling teaches.
| Element | Type | Who can write to it |
|---|---|---|
| Customer in the app chat | External entity | Anyone with an account, or who has taken one over |
| Assistant (model plus loop) | Process | Operator prompt by Owoleaf; the rest by the sources below |
| Help-centre articles | Data store | The content team, through its publishing process |
| Transaction and ticket lookups | Tools, read | Customers (their messages and tickets); the processor (status fields) |
| Refund tool | Tool, write | Reaches the card processor and the ledger |
| Human desk | External entity | Agents on the four queues: transfer, card, login, kyc |
| Card processor | External entity | Its webhooks carry charge and refund events |
Four boundaries matter. TB1 is the customer to the chat channel: authentication, and the session that proves who is asking. TB2 is untrusted text into the model’s context: the customer’s words, retrieved articles and tool results all cross it, and nothing on the far side can verify them. TB3 is the model’s output into the dispatcher: the new boundary, where a proposal becomes a candidate action. TB4 is the dispatcher into the money systems, where credentials, limits and the ledger live.
Most threats sit on TB2 and TB3.
STRIDE, read for an agent
STRIDE still works as a prompt. The questions are the same; the answers have a different texture.
| Threat | In the support agent | Where the control belongs |
|---|---|---|
| Spoofing | A message claiming to be the support lead or a policy update | Authority comes from the session and the desk tool, never from words in the chat |
| Tampering | A help-centre article edited to carry instructions; a tool result with attacker text in it | Outsider text is untrusted; publishing to the help centre needs review |
| Repudiation | A refund paid and nobody can say why | Log the conversation, the retrieved article ids, the tool arguments and results, and the ledger reference |
| Information disclosure | Another customer’s transaction or session ID; the operator prompt; a rendered link that carries data out | The tool takes its customer from the session, outputs are checked in code, and the prompt holds no secrets |
| Denial of service | A scripted conversation that loops, or floods the refund path; a bill that grows without limit | Budgets on steps, tokens and refunds per conversation, and a circuit breaker |
| Elevation of privilege | The agent doing what only a human with approval should be able to do | The autonomy ladder below, enforced in the dispatcher |
The OWASP Top 10 for LLM Applications (2025 edition) gives the same ground a second index, and the course chapter lists it in full. For this system, carry prompt injection, sensitive information disclosure, improper output handling, excessive agency, vector and embedding weaknesses and unbounded consumption into your table. Numbers change between editions, so cite a risk by name and edition. Excessive agency decides the size of the incident, and OWASP traces it to three roots: too much functionality, too much permission and too much autonomy. This chapter is mostly about the third.
The autonomy ladder: what may it do without a person
The business asks a yes or no question: can the agent issue refunds? The useful answer is a ladder, built one action at a time. Four properties decide where each action sits.
Reversibility. A message can be corrected. Money paid to a new destination often cannot.
Bound. The most the action can cost if every parameter is the attacker’s choice. Work it out as a number before anyone argues about likelihood.
Destination. Returning money to the card it came from gives an attacker nothing they did not already have; crediting a new account does.
Who chooses the parameters. Each argument the model fills in is one the attacker can influence, so shrink the list. A refund tool that takes only a top-up id, and works out the amount, card and customer itself, has one such parameter, and the code can check it against the processor’s record.
Put the actions on a ladder with four rungs. Read-only: lookups scoped to the session’s customer. Act within bounds: the tool does the thing, with parameters the code chooses and limits the code enforces. Propose, then a person approves: the tool records a request and a human on the desk decides. Never: no tool exists.
| Action | Reversible? | Destination chosen by | Rung |
|---|---|---|---|
| Look up the customer’s own transactions | Yes (read) | n/a | Read-only |
| Refund a failed card top-up to the same card | No, but returns money the customer already owned | The original card | Act within bounds |
| Refund a transfer fee (₦10, ₦25 or ₦50) | Hard | The customer’s wallet | Act within bounds, once per transfer |
| Credit the wallet, or refund to a different card or account | Hard | The model’s argument | Propose, then a person approves |
| Change a limit, a tier or a KYC record | Hard | n/a | Never |
| Ask for or repeat a PIN, password or OTP | n/a | n/a | Never, and a check in code rejects the output |
Owoleaf’s help centre already says a failed card top-up is refunded to the same card within 5 business days, or up to 14 for cards issued outside Nigeria. An agent that triggers that refund early, for the right top-up, changes timing and not entitlement, so it can sit on the middle rung. The rung is a property of the tool’s design, not a judgement of how well-behaved the model is.
Caps give the middle rung a ceiling you can state, and one defensible anchor is the limits the product already has. If no automatic path may move more to a customer than that customer could send in a day, the agent’s maximum is no worse than the account’s. Owoleaf’s daily send limits are ₦30,000 at tier 1 and ₦200,000 at tier 2, so a per-refund ceiling at the first figure and a daily total at the second can be defended in a review. Above them, the action moves to the approval rung. These are design choices for the threat model, not company rules: write them down with an owner who can change them.
Two more controls complete the rung. Idempotency: your code generates the key, usually from the tool call id, so a retried turn cannot pay twice; the idempotency lesson explains why. Re-check at the moment of action: read the processor’s status when the refund runs, not when the model looked it up, because a pending top-up can settle a second later. That is time-of-check to time-of-use in a new coat.
Approval is a control only if it is designed
The approval rung fails in three ways. The human sees the model’s rationale instead of the facts, so a persuasive paragraph does the deciding. The prompt buries the amount and destination, so the click is reflex. And volume turns the approver into a rubber stamp. Show the processor’s status, the destination, the amount and the customer’s history in plain words, and keep the model’s summary out of the decision. Measure the approval rate: near 100% means the control is not being exercised, the same signature as the rubber-stamped review in identity, access and secrets. Approval must live in the desk tool, because a chat message saying “approved” is text, and text is what the attacker controls.
Controls that hold, and controls that help
Sort every control you propose into three bins, and be honest about the bin.
| Kind | Examples | What it gives you |
|---|---|---|
| Structural | Tool allowlist per context; authorisation from the session in code; bounded or absent parameters; a narrow role per tool; an output renderer that drops unapproved links; approval in the desk tool; budgets | A guarantee: no text changes it |
| Probabilistic | Prompt rules; labelling of untrusted text; injection classifiers; a second model as reviewer | A lower failure rate, never zero; worth having as layers |
| Detective | Logs, anomaly alerts, reconciliation, sampling of transcripts | Finding out afterwards, and a way to size the loss |
A threat model that leans on the middle bin to close a high-impact threat has not closed it. Security philosophies calls the layers defence in depth, and they are welcome, but one structural control per high-impact threat is the minimum.
Owoleaf already has one detective control: it reconciles its ledger daily against the card processor’s settlement file. A refund the agent issued with no matching failed top-up and no refund event from the processor shows up as a break, with an OWL reference to trace. Tell the reconciliation owner what to look for; the reconciliation lesson shows the mechanics. It will not stop a bad refund, but it caps how long one goes unnoticed to about a day.
Credentials need their own pass. The model never holds a key: the tool server does, with a role that can call the processor’s refund endpoint and nothing else, short-lived where the platform allows it, per the secrets order in identity, access and secrets. The operator prompt holds no secret and no security logic you would mind seeing in public, because anything in the context can be coaxed out. If tools arrive through MCP servers, each is code running with your permissions: pin versions and treat a changed tool description as a changed interface. The MCP chapter covers the mechanics; vulnerability management and software supply chain security cover the packages underneath.
What to test
A guardrail with no test set is a hope, and so is a threat-model row. Build an attack set like a regression suite: each case names the threat id it exercises, the input and the expected refusal. Then pin down where the assertion lives.
A test that checks the model said “I can’t do that” proves almost nothing, because it may comply after the next prompt tweak or model upgrade. A test that checks the dispatcher rejected the call, or that the ledger shows no refund, proves a control. Write both, treat the second as the one that counts, and run the set on every change to the prompt, the model, the retrieval corpus or a tool definition. Building an eval set and evals in CI show how to wire that in.
Two habits earn their keep. Test in the languages your customers write in, since the assistant replies in the customer’s language and an English-only set measures a fraction of the surface. And track attack success rate per layer: if it is high with only the prompt rules and zero with the dispatcher in place, you know where your security lives.
Where practitioners disagree
| Question | One view | The other view |
|---|---|---|
| Can the model be made safe against injection | Training and classifiers will close most of the gap | Assume it is fooled and engineer the blast radius, as OWASP’s excessive agency guidance and Willison’s trifecta both argue |
| Human in the loop | A person on every consequential action | Approval at volume decays into a rubber stamp; bound the action in code and keep people for what code cannot bound |
| Architecture | Separate trusted and untrusted flows, as in the two papers in the reading | Those designs cost flexibility; start with allowlists and approval and move up where the stakes justify it |
| Frameworks | Anchor on the NIST AI Risk Management Framework so governance is auditable | Frameworks name risks; they do not say where the dispatcher goes |
Most mature teams do the plain version: structural controls on every write tool, approval where code cannot bound the destination, a framework for the paperwork, and a design pattern only for the highest-stakes flow.
Where agent security goes wrong
The review is a prompt review. The team shows you the system prompt. Ask for the dispatcher instead, and for every tool with its parameters and its credential.
The tool inherits an admin token. Reusing the existing service account was quicker. Now a fooled model has the whole account. Give each write tool its own narrow role.
A read tool returns attacker text. “Read-only” describes what the tool does, not what it returns. A ticket history or a free-text note carries outsider words into the context. Treat the result as untrusted, and keep write tools behind approval when such text is present.
The help-centre pipeline has no review. One edit to the retrieval store reaches every conversation. Give publishing the change control you give code that touches money.
No kill switch. Someone must be able to pause the write tools in minutes while the assistant hands over to a human. Drill it, as detection and incident response drills any playbook.
The set is stale. A model upgrade changes the system. Re-run the attack set.
Day to day
The work is an intake, a handful of reviews and a metric, repeated.
Intake, a few hours a week. AI features arrive through the usual design-doc process. Add three questions to the template: what tools does it call, what outside text can reach its context, and what is the most a fooled model can do. Features with write tools or private data in context get a session; the rest get a checklist.
The session, 60 to 90 minutes. Run it as in threat modelling, with the tech lead, the builders and the owner of the business process. For the support agent that is the support lead, who decides what the desk can absorb and accepts the residual risk. Draw TB2 and TB3 explicitly. Fill the autonomy ladder before the STRIDE table: the ladder is the design change, the table is the evidence.
Weekly. Read a sample of transcripts for the highest-risk flows, with the tool arguments beside the text. Check the approval rate and the override rate, and the reconciliation breaks tied to agent refunds.
On every change. The attack set runs in CI on any change to the prompt, model, corpus or tool definition, and a failed structural test blocks the release.
Monthly. Report automatic refunds per thousand conversations, the share routed to approval, the approval rate, attack success rate per layer and the date of the last kill-switch drill.
Quarterly. Revisit the model whenever a tool is added, and at least quarterly for a money-moving agent as a rule of thumb. Run a tabletop where the agent pays out wrongly and the team must pause it, find the cause and tell customers.
The meetings that matter are the design review, where a new tool is cheapest to change, and the support operations review, where you hear what the desk sees.
There is no security engineer, and the agent was built in a week by whoever knew the API. Your levers are the two cheapest: shrink what the tools can do, and keep money out of the model’s hands. One narrow role per tool, no amount or destination parameters on refunds, a human click for anything else, and a switch the founder can flip. Write the autonomy ladder in a short document and keep a dozen attack cases in the repository. A formal framework would cost more than the product earns.
You are building the programme. The support agent is the first of several, so write the intake questions into the design-doc template and a reusable tool-review checklist that engineers can fill in themselves. Start the shared attack set and wire it to CI. Customers’ security questionnaires begin to ask how the agent is controlled, and SOC 2 auditors ask who approves changes to prompts and tools. Train two engineers to run the sessions so every new agent does not wait for you.
Agents multiply across teams, vendors and platforms, and the problem is inventory and consistency. You need a register of every agent with its tools, credentials and owner, a standard for which autonomy rung needs which approval, and a central gateway for model and tool traffic where logging and kill switches live. Frameworks such as the NIST AI Risk Management Framework become the language of governance, and risk committees expect evidence. The politics are teams that want their agent to act freely and a business owner who must sign the acceptances.
Template
# Agent threat model: <agent and the change>
Author · Facilitated with: <tech lead, engineers, business owner> · Date · Design doc: <link>
Status: draft | reviewed | controls in progress | closed
## 1. What the agent can reach
**Purpose and users:** <who talks to it, what it is for>
**Authority it acts with:** <service identity, roles, credentials, lifetime>
**Text sources in its context:**
| Source | Who can write to it | Trusted? |
|---|---|---|
**Tools:**
| Tool | Read or write | Parameters (who chooses each) | Credential | Worst case if every parameter is hostile |
|---|---|---|---|---|
### Data-flow diagram
<ASCII or link. Mark: TB-context (untrusted text into the model), TB-dispatch (model output into the dispatcher), TB-money (dispatcher into systems of record).>
## 2. What can go wrong
| ID | Element / flow | STRIDE | OWASP LLM risk | Threat (actor, action, impact; how the text gets in) | Likelihood H/M/L | Impact H/M/L |
|---|---|---|---|---|---|---|
## 3. Autonomy ladder
| Action | Reversible? | Destination chosen by | Rung (read-only / act within bounds / propose and approve / never) | Cap and why | Approver |
|---|---|---|---|---|---|
## 4. Controls and evidence
| Threat | Structural control | Layers (probabilistic, detective) | Ticket | Owner | Test (asserts dispatcher or ledger) |
|---|---|---|---|---|---|
## 5. Residual risk
| Risk | Why we accept it | Accepted by | Review date |
|---|---|---|---|
## 6. Operating the agent
Kill switch: <what it pauses, who can flip it, last drill>
Metrics: <auto actions per 1,000 conversations, approval rate, attack success rate per layer>
Re-run the attack set when: <prompt, model, corpus or tool change>
**Revisit when:** <new tool, new text source, new destination> WORKED EXAMPLE
Owoleaf at 200 people is the Lagos wallet, 44 engineers in six teams. Bisoye, a security engineer, ran a 75-minute session with the tech lead, two engineers and Chiamanda, the support lead, on adding refunds to the support assistant. The assistant already answers from retrieved help-centre articles, in the customer’s language.
Tools. lookup_transaction(customer from session): read-only. refund_failed_topup(top_up_id): no amount, card or customer parameter; the code finds the owner from the session, reads the processor’s status at the moment of the call, refunds the original amount to the original card, and uses the tool call id as the idempotency key. refund_transfer_fee(transfer_id): credits the fee that transfer was charged (₦10, ₦25 or ₦50), once per transfer. handoff_to_human(queue): transfer, card, login or kyc.
[Customer] -> ||TB-ctx|| -> (Assistant: model + loop) <- [[Help-centre articles]]
|
||TB-dispatch||
v
(Dispatcher: session, caps, allowlist)
|
||TB-money|| -> [Card processor] , [[Ledger OWL-nnnn]]| ID | Where | STRIDE | Threat | Response and control | Ticket |
|---|---|---|---|---|---|
| T1 | Dispatcher | E | Customer writes ‘refund top-up 4471’ for a top-up that is not theirs | Mitigate: owner taken from session, tool refuses; negative test asserts the ledger is unchanged | AGT-11 |
| T2 | Help-centre store | T | An edited article tells the assistant to refund any top-up the customer names | Mitigate: tool refunds only failed top-ups to the original card; publishing needs a second reviewer | AGT-12 |
| T3 | Dispatcher | E | Many small refunds in one conversation | Mitigate: ₦30,000 per refund (the tier-1 daily send limit), ₦200,000 per customer per day (the tier-2 limit); above either, handoff | AGT-13 |
| T4 | Output | I | The assistant is coaxed into asking for an OTP | Mitigate: output check in code rejects messages that ask for a PIN, password or OTP | AGT-14 |
| T5 | Loop | D | A scripted conversation loops on refunds | Mitigate: step and token budget per conversation; circuit breaker pauses refunds if the hourly count passes the busiest hour of the last 30 days plus 50% (a starting point) | AGT-15 |
| T6 | Logs | R | A refund is disputed and cannot be explained | Mitigate: log conversation id, article ids, tool arguments and results, and the OWL reference | AGT-16 |
Detective control. Daily reconciliation against the processor’s settlement file: an agent refund without a failed charge and a refund event is a break, reviewed the next business day.
Accepted risk. A customer whose top-up the processor marks failed, then settles within seconds, may be refunded and keep the funds; the re-check at call time narrows the window but cannot close it. Accepted by Chiamanda, with a review date of three months, or sooner if reconciliation breaks tied to the agent exceed one a week. Revisit when a tool can credit a wallet or the assistant gains any outbound channel.
Now you
You are the security engineer at Owoleaf at 200 people. Product wants the support assistant to credit a customer’s wallet at once when a card top-up fails, instead of waiting for the card refund, which the help centre says takes up to 5 business days, or up to 14 for cards issued outside Nigeria. Chiamanda, the support lead, backs it because customers hate the wait. Launch is in three weeks. Complications: if the processor later reports the top-up as successful, the customer holds the money twice, and a fraudster can spend the credit and let the card refund land too; the content team edits help-centre articles through a CMS with no review step; the assistant answers in whatever language the customer writes, and the injection tests the team has are English only; the assistant’s tool calls are logged without their arguments; and product says approval on every credit would make the feature pointless. Write the threat model: the DFD with its boundaries, a STRIDE table covering the credit, the CMS, tool results and language, the autonomy ladder with caps, and the residual risks with who should accept them.
Self-check
You are the security engineer at Owoleaf at 200 people. The support assistant answers well in the customer's language, and Chiamanda wants it to issue refunds without a human on every case. Failed card top-ups, the largest and cleanest category, are refunded to the same card. Launch is in a month and the desk is overloaded. The head of engineering asks what the agent may do without a person.
- DOC LLM06:2025 Excessive Agency OWASP GenAI Security Project, 2025
The risk that sets the size of an agent incident, with its three roots (functionality, permissions, autonomy) and the prevention list. Read it beside the autonomy ladder and check each tool against it.
- POST The lethal trifecta for AI agents Simon Willison, 2025
The shortest practical framing of when an agent can be made to leak data: private data, untrusted content and a way to communicate outward. Use it as a quick screen during intake.
- PAPER Design Patterns for Securing LLM Agents against Prompt Injections Beurer-Kellner et al., 2025
Architectural patterns that stop untrusted input from triggering consequential actions, applied to worked agent applications. Read it when allowlists and approval are not enough for a high-stakes flow. Read: The abstract and the case studies, to see how each pattern trades utility for security.
- PAPER Defeating Prompt Injections by Design (CaMeL) Debenedetti et al., 2025
A research design in which a custom interpreter tracks where each value came from and enforces policies on tool use. A model of what a real boundary looks like, and of what it costs. Read: The abstract and the sections on the interpreter and its security policies.
- DOC Artificial Intelligence Risk Management Framework: Generative AI Profile (NIST AI 600-1) NIST, 2024
Voluntary guidance that maps twelve generative AI risks to the AI Risk Management Framework's Govern, Map, Measure and Manage functions. Useful for the governance and audit conversation, not for deciding where the dispatcher goes.
- POST BC tribunal confirms companies remain liable for information provided by AI chatbot American Bar Association, Business Law Today, 2024
A summary of Moffatt v. Air Canada: the tribunal held the company responsible for what its chatbot said. The case to cite when someone argues that the agent's output is not the company's act.
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.