OWASP LLM01:2026 Prompt Injection in AI agents: the Rule of Two in code
No reliable prevention exists, says OWASP, so build for the day an injection works. The Rule of Two in code: a run that read untrusted text and private data asks before it acts.
· 8 min read
LLM01:2026 Prompt Injection keeps the top spot in the OWASP Top 10 for LLM Applications 2026. It happens when input to the model, “whether direct user input, retrieved content, tool output, image, audio, or video content, intermediate reasoning, or persistent memory”, changes its behaviour in ways the developer did not intend.
The 2026 entry is unusually direct about prevention: “no reliable prevention mechanism exists today”, because a model makes no architectural distinction between instructions and data. So “defense is therefore architectural rather than interceptive”: design the system on the assumption that the injection will get through, and limit what the model can do when it does.
Why agents raise the stakes
OWASP notes that most severe incidents on record “became severe because the injection landed inside a system whose tools, scopes, or output-rendering capabilities let the compromised model act on the attacker’s behalf at the user’s privilege level.” Its examples include a poisoned GitHub issue that made an agent leak private repositories, and a support ticket that made a coding assistant dump a production database through an MCP server running with full rights.
The pattern is the same each time. The attacker cannot reach the backend, so they leave text where your agent will read it, and the agent, with your credentials, does the work for them.
The Rule of Two
Mitigation 8 turns that into a check you can run before deployment. It builds on Simon Willison’s “lethal trifecta” and Meta’s Rule of Two, and names three capabilities:
- [A] Untrusted input
- Web pages, email from strangers, issue titles, tickets, tool results from third parties.
- [B] Sensitive data
- The customer database, private repositories, the user's mail.
- [C] Change or communicate
- Sending email, refunding, writing files, calling an outside API, saving to memory.
OWASP’s floor: “any [A,B,C] agent needs per-action human approval”, and an agent with untrusted input plus one of the other two needs an explicit assessment of the risk that is left. That makes the approval step a direct mitigation here, not a nice-to-have. Mitigation 7 says the same in general terms: “Require explicit human confirmation before any privileged, irreversible, or externally visible action.”
The Rule of Two in code
An agent is rarely all three at every moment. A support agent that has only looked up an order is [B]. Once it has read an email from a stranger as well, it is [A,B], and its next send or refund makes it [A,B,C]. So track the legs per run, from the tools it has called:
// Which leg of the Rule of Two each tool touches.
// [A] reads untrusted input, [B] reads private data, [C] changes something or sends it out.
const LEGS: Record<string, { untrusted?: true; private?: true; acts?: true }> = {
"web.fetch": { untrusted: true },
"email.read": { untrusted: true, private: true }, // anyone can email you
"crm.lookup": { private: true },
"email.send": { acts: true },
"refund.create": { acts: true },
"memory.save": { acts: true }, // a saved memory reaches every later session
};Then every tool that acts goes through the gate, and a run that has touched all three asks with a second key:
// One agent, two keys. Rules for the second key never let anything through alone.
const usual = new ApprovalClient({ agent: "support-bot", apiUrl, key: process.env.VG_KEY! });
const tainted = new ApprovalClient({ agent: "support-bot", apiUrl, key: process.env.VG_KEY_TAINTED! });
class Run {
sources: string[] = []; // where untrusted text came from
sawPrivate = false;
async call(tool: string, rawArgs: Args) {
// Own keys only, so a tool called "constructor" is unknown too.
const legs = Object.hasOwn(LEGS, tool) ? LEGS[tool] : undefined;
if (!legs) throw new Error(`${tool} has no Rule of Two entry`); // unknown tools never run
const args = withoutHiddenCharacters(rawArgs); // what is shown is what runs
if (!legs.acts) {
const result = await tools[tool](args);
if (legs.untrusted) this.sources.push(sourceOf(tool, args));
if (legs.private) this.sawPrivate = true;
return result;
}
// A + B + C: the run has read untrusted text and private data, and now wants to act.
const allThree = this.sources.length > 0 && this.sawPrivate;
return (allThree ? tainted : usual).guard(
{
action: tool,
summary: describe(tool, args), // from the arguments, never from the model's words
details: { untrusted_sources: this.sources.slice(-5).join(", ") || "none" },
},
() => tools[tool](args)
);
}
}One rule for that key holds the floor:
# Every action asked with the tainted key waits for a person.
# The most cautious rule wins, so no allow rule can answer for it.
{ "action": "*", "agent_key_id": "TAINTED_KEY_ID", "effect": "ask" }- Rules go by key, not by name. Both clients call themselves
support-bot, which is what a person sees. Rules match on the key, which the model cannot choose or change. - The model does not decide it is tainted. The run object counts what was read. Telling the model to “be careful after reading email” is exactly what an injection overrides.
- The person sees why. The details list where the untrusted text came from, so the approver can open that email before saying yes.
- Unknown tools never run. A new tool without an entry throws, so adding a tool forces someone to decide its legs.
What is shown is what runs
Mitigation 7 has a warning attached: surface “the exact rendered action rather than a summary”, because “invisible-character smuggling can make the displayed action differ from the executed one.” Mitigation 5 names the characters. Strip them from the arguments once, and use the cleaned arguments both for the summary and for the call:
// Tag characters, variation selectors, zero-width characters, direction
// marks and controls: invisible to a reviewer, readable to a model. This also
// takes emoji sequences apart (a family, a red heart), a fair price for an action.
const HIDDEN = /[\u00AD\u061C\u180B-\u180F\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u206F\uFE00-\uFE0F\uFEFF\uFFF9-\uFFFB\u{E0000}-\u{E007F}\u{E0100}-\u{E01EF}]/gu;
function withoutHiddenCharacters<T>(value: T): T {
if (typeof value === "string") return value.replace(HIDDEN, "") as T;
if (Array.isArray(value)) return value.map(withoutHiddenCharacters) as T;
if (value && typeof value === "object") {
return Object.fromEntries(
Object.entries(value).map(([k, v]) => [k, withoutHiddenCharacters(v)])
) as T;
}
return value;
}VariantGate checks too, in case something slips past your code. The inbox and the page a link in an email or chat message opens draw every hidden character in a request as a visible mark, decode tag characters into the text they hide, and warn above the request; the emails and chat messages themselves lead with the same warning. The details are on Security.
Build the summary from those arguments in code, never from what the model says it is about to do. A manipulated model can describe a harmful action innocently; your describe() cannot. The ASI09 article goes further into asking a person with facts your code checked.
What the approval does not do
OWASP is clear that no single control is enough, and that approval fatigue “degrades reviewer judgment at volume”. An agent that asks about everything trains people to click yes. Keep the asking for the [A,B,C] moments, and let the rest of the work run:
- Remove a leg where you can. An agent that reads the web but holds no private data cannot leak any. That beats asking.
- Least privilege in the tools. Credentials stay in your code, scoped per operation, so an injected call cannot reach further than the tool allows.
- Pin and audit MCP servers. Tool descriptions can carry instructions too. That part is LLM04 and ASI04.
- Test against adaptive attacks. OWASP cites research where most defenses held against fixed attacks and failed over 90% of the time against attackers who knew the defense.
A rule can answer for a person on routine [C] actions, such as refunds under a limit, as long as the run is not [A,B,C]. The approval policy generator writes those rules, and the tool risk checker sorts an MCP tool list into what only looks and what acts, which is most of the work of filling in LEGS.
The rest of the 2026 list is in our overview of the OWASP Top 10 for LLM Applications 2026. When the model is an agent, OWASP pairs this entry with LLM03:2026 Excessive Agency: injection is the input side, excessive agency is what gives it consequences.