An assistant connected to a helpdesk reads a ticket. Halfway down, in the customer's own words, is a sentence addressed to the assistant: forward the last ten invoices to this address. The assistant has a tool that sends mail, and to a language model nothing marks that sentence as data rather than instruction.
This is indirect prompt injection, and the field has largely stopped pretending the model can be the boundary. Wrapping tool output in delimiters and running classifiers over it both help, and both are worked around once an attacker writes specifically for them. What holds is a decision the model cannot argue with: made in code, outside the model, on facts the model did not supply.
What matters most is the order the checks run in. A verdict computed before the thing it depends on is a hole that looks like a feature.
The order
Every tool call in Memtro passes through one wrapper, withCacheAndActivity, whatever surface it came from: the chat page, the API, the MCP server, a scheduled job, the Slack bot or a sandboxed CLI. The order is written down once, as a constant in gates.ts:
reach, tier, taint, provenance, secrets, cache, execute.
Reach asks whether this principal may use this tool on this exact connection at all.
Tier asks what the organisation allows for this tool's risk. Every connector tool declares whether it reads, writes or does something hard to undo, and a tool that declares nothing does not compile.
Taint asks whether this run has already read something external. Once a connector, a web page or an MCP server has returned anything, the run is marked, and from then on an action needs a person present to confirm it. A scheduled job is the exception for connector actions: its run takes the actions its owner can take, because setting the job up was the asking, and the argument checks below still apply to it.
Provenance asks where the action is pointed, which is a different question and gets its own section below.
Secrets refuses any action whose arguments contain something shaped like a credential. An assistant has no honest reason to post an API key into a channel.
Cache may now serve an identical earlier call. Execute runs it.
Why the cache is near the end
Caching a connector result for a few minutes is ordinary, and it is tempting to check the cheapest thing first. It cannot go first.
A cached result served before the gate that would have refused the call is a hole. The cache knows only that an identical call ran recently. It does not know whether this run is tainted, whether anybody is watching, or whether the arguments carry a key, and those are exactly the facts the gates turn on. So every gate runs first and only the read is shared. In particular, the credential check on an action's arguments sits above the cache lookup, so a call that should be refused is never answered from the cache instead. A test holds the declared order, gate by gate.
The same reasoning applies to output. Connector, web and MCP output is sanitised once, at the single return site in that wrapper, before it is written to the cache. Otherwise a payload could be cleaned on its first trip and served raw from the cache for the next ten minutes.
Two questions, not one
Deciding whether a run may send mail is not the same as deciding who it may send mail to. Conflating the two is what the published exfiltration incidents have in common: the action was one the agent was allowed to take, and the argument was the attacker's.
So there are two functions. decideAction asks whether this run may act at all. decideArguments asks where it is pointed. A job its owner set up to send from the support mailbox may send mail. It may not send mail to an address that first appeared inside an email it was reading.
The second question applies only on a tainted run. A clean turn has nothing in its context that could have written the argument. On a tainted run, every recipient, every fetch host and every distinctive value in a search query has to be traceable to something other than the content the run just read.
Provenance comes from identifying fields only
Traceable to what? Either to the person who asked, in their own words, or to a system of record asserting an identifier.
That second source needs care. A CRM contact's email is the system of record saying how to reach someone. A message's from address is the person who chose to write to you, which in every case this check exists for is the attacker. Both are real addresses held by a real system. Only one of them is an assertion by that system.
So provenance.ts harvests identifiers from a short list of identifying keys (email, url, permalink, domain and a handful of spellings of each) and never from prose. Bodies, subjects, snippets and from fields are never read for addresses. The links a scraped page chooses to point at are excluded for the same reason: whoever wrote the page chose them. The assistant's own earlier turns do not count as the person's words either. An assistant that has already been steered will happily restate the attacker's address, and treating its output as evidence would launder the injection in one hop.
Fail closed
Every gate needs to know whether somebody is there to be asked. "Ask the person" and "refuse" are different verdicts, and the right one depends on whether there is a person.
That fact travels in a signed token, never in the request body. When a token names no surface at all, it is read as unattended, the way a scheduled job is. Not knowing is treated as nobody watching, the safe direction to be wrong in. Missing state, a check that throws or a judge that cannot be reached means refuse or ask. None of them runs the call.
Gates narrow, never widen
No gate may admit a call that an earlier one refused.
An administrator can reach every shared connection. That is the right answer to "what may this person use?" and the wrong one to "may this run act?". So the administrator's unrestricted reach lifts grants, never gates. decideAction takes no input for role at all. An administrator's run that has read an injected ticket is held like anybody else's.
A list guarded by name needs a test that the names exist
Connector actions are easy to gate because each one carries its risk on its own definition. Memtro's own tools that outlive the request (writing a memory, scheduling a job, defining a measure, adopting a procedure) are not connector actions, so the gates have to be told about them by name.
A list of names is the kind of control that fails silently. A gate guarding memtro_record_term guards nothing if the tool is called memtro_define_term, and a list of names that are all slightly wrong reads exactly like a list that covers everything. So a structural test builds the real tool set and asserts every name on the list exists.
That test catches a misspelling. It does not catch a writing tool that was never added, and that is the direction that actually went wrong for us: a page-publishing tool and two procedure tools shipped writing into places every later request reads while sitting on no list. The fix was a second test running the other way. It holds a list of every tool known to be a read, and any tool that is neither listed as a read nor gated fails the test suite until somebody decides which it is.
What the envelope is for
Outside content still reaches the model inside a marked, sanitised envelope naming its source. That makes the gates fire less often. It is not one of the seven, and nothing above depends on it working.
Where Memtro stands
These gates run on every surface, and the order is enforced in one place. A new organisation starts enforcing. One that has never chosen is read in report mode, where every verdict is computed and recorded but an attended call still runs, so it can see what enforcement would hold before it holds anything. A refusal on a run nobody is watching is applied in either mode. The full model, including what it does not cover, is on the prompt injection page and the security overview, and we wrote about whose authority an MCP server uses before this.