A stateless model forgets you the moment the conversation ends. That is safe, and it is also limiting: the model cannot remember your preferences, your project, or what it did five minutes ago. So we give agents memory: a short-term working context and a long-term store that survives across sessions. Memory is what makes an agent behave like an assistant. It is also an attack surface, because persistence, the property that makes memory useful, is the property an attacker wants for a payload.
Two kinds of memory, two different risks
Short-term memory is the context window: the running transcript of the current session, plus recent tool output. It is bounded, it is discarded when the session ends, and its risk is the familiar one: the model reads everything in that window, including retrieved documents and tool results, as one flat stream. A prompt injection here is bad, but it dies with the session.
Long-term memory is the dangerous one. To remember across sessions, the agent writes summaries or facts into a persistent store, usually a vector database or a record keyed to the user, and retrieves them back into context in future sessions. A fact learned today is meant to shape behavior next week. If that fact is a lie, or an instruction, planted on purpose, it survives the session and is retrieved into later ones.
Memory poisoning: injection with a long fuse
Ordinary prompt injection works once, in the moment. Memory poisoning is injection with persistence. The attacker gets a malicious statement written into long-term memory, through a message the agent chooses to remember, a tool result it summarizes, or a document it processes. From then on that statement is retrieved and re-presented to the model as trusted, first-party context. Security researchers have demonstrated this against consumer assistants with memory features. In one 2024 case, a web page made the ChatGPT macOS app store an instruction that sent later conversation text to an attacker's server.
Memory poisoning also launders trust. Text that arrived as untrusted input on Monday can, by Thursday, look the same as something the user told the agent to remember, because the provenance is gone. The model treats “the user prefers replies sent to this address” as a settled fact, never knowing an attacker wrote it. A poisoned entry can also fire only under specific conditions, so it can stay dormant through your tests.
Memory can also become a data-leak reservoir. Long-term stores accumulate sensitive fragments (names, tokens, internal facts), and if memory is shared across users or tenants, or retrieved without scoping, one user's remembered secrets can surface in another's session. Persistence keeps what you want and what you do not.
Containing what the agent remembers
- Track provenance into memory. Record where a remembered fact came from, and never let text that entered as untrusted input graduate to trusted instruction just because time passed.
- Scope memory to an identity. Key long-term memory strictly to the user or tenant and filter recall the same way, so one principal's memory can never surface for another.
- Gate writes. Be deliberate about what gets persisted; the less that enters long-term memory, the less an attacker can plant there.
- Make memory inspectable and revocable. You need to see what an agent has stored and delete a specific record. A memory you cannot audit is a persistence mechanism you cannot clean.
Memory is worth building. Persistence mechanisms in other systems (startup items, scheduled tasks) have also served attackers as hiding places, and agent memory adds the risk that untrusted text becomes trusted recollection. You cannot clean a memory you cannot see, and you cannot govern memory you never knew an agent was keeping.