Memory poisoning: the slow attack on AI agents that grids saw first
How persistent memory poisoning works on AI agents, why it mirrors stealthy grid data attacks, and how to detect drift with baselines, provenance and audits.
An agent that remembers is an agent that can be quietly reprogrammed. That is the short version of this post.
Most prompt injection discussion assumes the attack lives and dies inside one conversation. Memory removes that assumption. Once an agent can write to long-term memory or a retrieval store, a single malicious input can become a standing instruction that runs every day, for every future session, long after the original email or web page is gone.
I spent my PhD studying a very similar problem in power grids: attackers who slowly feed false measurements that pass every per-sample check. The defenses that worked there carry over surprisingly well to agent memory. This post connects the two.
If you are new to the root cause, start with my guide on why AI agents can’t tell instructions from data. Memory poisoning is what happens when that flaw gets a hard drive.
What is memory poisoning in AI agents?
Memory poisoning is an attack that writes malicious instructions or false facts into the state an agent carries across sessions. That state can be a chat assistant’s saved memories, an agent’s long-term memory store, or the document collection behind retrieval-augmented generation (RAG).
It is now formally recognized. The OWASP Agentic AI Threats and Mitigations guide (v1.0, February 2025) lists Memory Poisoning as threat T1, and test tools such as the promptfoo memory poisoning plugin map directly to it. The OWASP Top 10 for LLMs 2025 includes LLM04 Data and Model Poisoning and added LLM08 Vector and Embedding Weaknesses. NIST AI 100-2e2025 covers RAG knowledge-base poisoning and indirect prompt injection in its adversarial ML taxonomy.
How does persistence change the threat model?
In a session-scoped threat model, the blast radius of an injection is one conversation. Close the chat and the attack is gone.
With persistent memory, the injection only has to succeed once. After that, it replays. Two public cases show this clearly.
SpAIware (2024). Security researcher Johann Rehberger showed that prompt injection from untrusted data could plant false memories in ChatGPT that kept exfiltrating chat content in later sessions, as reported by The Hacker News. The exfiltration vector was fixed in ChatGPT macOS version 1.2024.247, and users were advised to review their stored memories.
ZombieAgent (2025/2026). Radware researchers chained indirect prompt injection through ChatGPT Connectors with the Memory feature for persistence. According to SecurityWeek, the attack needed no user action beyond normal conversation, and planted memory rules made ChatGPT read an attacker’s email and execute its instructions every time the user sent a message. It was reported through BugCrowd in September 2025 and patched on December 16, 2025.
The third case is the most worrying for anyone building agents. MINJA (NeurIPS 2025) showed that an ordinary user can inject malicious memory records through queries alone. No write access to the memory store is needed. If your agent learns from its interactions, every user is a potential writer.
So persistence changes three things:
- Time. The attack outlives its input. Logs from the day of the injection may be long rotated out by the time behavior goes wrong.
- Scope. One write affects every later session, and in shared memory, possibly every user.
- Attribution. The bad behavior shows up far from its cause, so incident response has to reconstruct history, not just inspect a single prompt.
Where can an agent’s memory be poisoned?
I find it useful to separate three surfaces.
1. Assistant memory. The saved facts and preferences a chat assistant keeps about a user. SpAIware and ZombieAgent targeted this layer.
2. Agent long-term memory. Records an agent writes about past tasks, successful plans or user context, which it retrieves to guide future actions. MINJA targets this layer.
3. The RAG knowledge base. The documents an agent retrieves at answer time. This is often the largest and least watched surface.
The research numbers for the last two are sobering:
- PoisonedRAG (USENIX Security 2025) reached a 97% attack success rate on the Natural Questions benchmark by injecting just 5 texts per target question into a database of about 2.68 million clean texts (about 90% across its benchmarks). Paraphrasing and perplexity-based defenses were not enough to stop it.
- AgentPoison (NeurIPS 2024) planted a trigger-based backdoor in agent memory or the RAG knowledge base. It achieved 82% retrieval success and 63% end-to-end attack success at a poisoning ratio under 0.1%, with under 1% degradation on benign tasks.
That last detail matters most. Under 1% benign degradation means normal quality metrics will not move. The system looks healthy right up until the trigger appears.
Why did power grids see this attack first?
Power grid operators run state estimation: they take thousands of sensor measurements and estimate the true state of the system. To catch broken sensors, they use residual-based bad data detection. If a measurement disagrees too much with what the physics says, it gets flagged.
In 2009, Liu, Ning and Reiter showed at ACM CCS that an attacker who crafts false data to fit the grid’s structure can pass that check entirely. Each injected measurement is consistent with the model, so the residual stays small. The check is doing exactly what it was designed to do, and it still misses the attack.
My own research picked up from there, in two directions.
First, the attacker does not need the grid’s blueprint. In Stealth false data injection using independent component analysis in smart grid (IEEE SmartGridComm 2011), we showed that an attacker without prior knowledge of the grid topology can infer its structure from observed measurements alone, then use it to launch stealthy attacks.
Second, detection has to look beyond individual samples. In Detecting stealthy false data injection using machine learning in smart grid (IEEE Systems Journal), we used distributed SVM classification and an unsupervised method that detects statistical deviation in measurements to catch attacks that residual checks miss. In Detecting false data injection attacks on power grid by sparse optimization (IEEE Transactions on Smart Grid, 2014), we modeled normal measurements over time as low-rank and attacks as sparse, and separated the two. The attack is invisible in any single snapshot but stands out against the structure of normal behavior across a time window.
The lesson I took from that work: checking each input against the rules is not enough. You detect stealthy manipulation over time, against a baseline of normal. I wrote more about this bridge in stealthy attacks from the smart grid to LLMs, and the full paper list is on my research page.
How does the grid analogy map to agent memory?
| Power grid concept | Agent memory equivalent |
|---|---|
| Residual-based bad data detection | Per-entry content filters on memory writes or retrieved chunks |
| Stealthy false data injection that fits the system model | Context-triggered poisoned memories that look benign in isolation |
| Attacker learns topology from observed data (ICA) | Attacker learns how memory works through queries only (MINJA) |
| Low-rank normal plus sparse anomaly over time | Outlier memories and behavior against a baseline |
| Trusted meter and sensor provenance | Provenance and trust tags on every memory write |
The second row is the important one. The A-MemGuard authors note that context-triggered poisoned entries are hard to spot when entries are audited one at a time. That is the agent version of passing the residual check. Each memory looks reasonable. The harm only appears in combination with a specific context.
How do you detect memory poisoning and drift?
If per-entry checks are the residual test, then detection needs the equivalent of the time-window methods. Here is what that looks like in practice.
Provenance on every write. Record where each memory came from: the user directly, a tool output, a connector, a retrieved document, or the agent’s own summary. Attach a trust level. Without this, you cannot answer the first incident-response question, which is “how did this get here?”
Baselines and snapshots. Keep hashed snapshots of memory state so you can tell exactly what changed and when. The OWASP Agent Memory Guard project sits between an agent and its memory store and, as Help Net Security describes it, uses SHA-256 baselines to flag tampering, declarative policies, and point-in-time snapshots that let an operator roll memory back to a known-good state.
Periodic memory audits and diffs. Diff memory against the last known-good snapshot on a schedule. Look for new standing instructions (“always”, “every time”, “before answering”), new external destinations such as URLs or email addresses, and entries whose provenance is a tool or connector rather than a user.
Cross-memory validation. Check entries against each other rather than alone. A-MemGuard combines consensus validation with a dual memory structure and reports cutting attack success rates by over 95%.
Behavioral drift monitoring. Track what the agent does, not only what it stores: which tools it calls, which domains it contacts, how often it reads particular sources. A memory rule like ZombieAgent’s, which made the assistant read an attacker email on every message, would show up as a sudden, persistent change in tool-call patterns.
What controls should teams deploying agents with memory put in place?
A practical checklist, roughly in order of effort:
- Gate memory writes. Do not let tool output or connector content trigger memory writes without user confirmation. In both SpAIware and ZombieAgent, persistence came from memory writes triggered by untrusted content, which is exactly what this control targets.
- Separate connectors from memory. Untrusted content arriving through email, documents or web tools should not share a write path with long-term memory.
- Tag provenance and trust. Every memory record and every RAG chunk carries its source and a trust level, and retrieval respects it.
- Snapshot and hash. Keep baselines of memory and knowledge-base state so you can diff and roll back.
- Add expiry and rollback. Give memories a time to live. Make restoring a known-good state a routine operation, not an emergency project.
- Audit on a schedule. Review memory diffs regularly, and tell end users to review their stored memories, as was advised after SpAIware.
- Monitor behavior for drift. Alert on persistent changes in tool use and outbound destinations.
- Apply least privilege. An agent that cannot send email cannot be turned into an email exfiltration channel.
- Red-team for persistence. Include memory-poisoning tests (for example the promptfoo plugin) and test across sessions, not only within one.
- Map to standards. Use OWASP Agentic T1, LLM04 and LLM08, and NIST AI 100-2e2025 to frame the risk for your security and governance teams.
Do not rely on filters alone. PoisonedRAG showed that perplexity and paraphrasing defenses were not enough, and AgentPoison’s poison barely moved benign performance. The same thing happened in grids: the per-sample check was never going to be the whole answer.
Memory poisoning also overlaps with training-data poisoning, where the corruption sits in the model rather than its memory. I cover detection methods for that case in how to detect poisoned training data.
The takeaway
Treat agent memory like grid telemetry. It is useful, it is necessary, and it is trustworthy only when its history is consistent. Know where every entry came from, keep a baseline of normal, and look for change over time rather than trusting each entry on its own.
Grid researchers learned more than a decade ago that a stealthy attacker designs inputs to pass your checks. Agent builders should assume the same, and design memory for auditability from day one.
Mohammad (Mike) Esmalifalak, PhD (Electrical Engineering, machine learning research, University of Houston), is a Lead Data Scientist in Toronto working on industrial machine learning. His research on stealthy false data injection detection in smart grids is listed on his research page.
Frequently asked questions
What is memory poisoning in AI agents?
It is an attack that writes malicious instructions or false facts into an agent's persistent memory or knowledge base, so the agent acts on them in later sessions long after the original malicious input is gone. OWASP lists it as threat T1 for agentic AI.
How do you detect a poisoned RAG database or agent memory?
Per-entry filters are not enough. Record provenance on every write, keep hashed snapshots and baselines of memory, diff and audit memory on a schedule, cross-validate entries against each other, and watch the agent's behavior for drift from a known baseline.
How can I prevent memory poisoning in ChatGPT or other agents?
Review stored memories regularly, and for agents you build, block memory writes driven by tool or connector content unless a user confirms them, keep connectors and memory separate, add expiry and rollback, and red-team with memory-poisoning tests.