AI Memory Poisoning Lab: Plant an Instruction for Next Session

✨ AI Summary
MemBot has a 'remember this' feature that stores facts about you and loads them into the system prompt every new conversation. If you can get an instruction stored as a 'fact', it rides into the system prompt next session and the bot treats it as its own rule.
Lab at a glance: Intermediate · 100 XP · about 15 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

Memory poisoning is persistent prompt injection. A feature that re-injects user-supplied content into the system prompt gives the attacker a durable channel: plant an instruction once, and it is reloaded with system authority in every later session.

The lesson: stored memory is user input that becomes part of the prompt. If it is not treated as inert data, it becomes a standing instruction.

How MemBot remembers facts

You tell MemBot to remember something; it stores the text and loads it into the system prompt on future conversations. A 'memory' phrased as an instruction therefore appears among the bot's own rules next time.

The attack approach

  • Use the remember feature to store a 'fact' that is actually an instruction.
  • Phrase it to override the bot's secrecy rule on the next session.
  • Start a fresh conversation so the poisoned memory loads.
  • Ask the question that triggers the planted instruction.

Full walkthrough (spoiler)

If it does not fire next session, the memory was not stored as you expected — open the steps.

Show the step-by-step solution
  1. Ask MemBot to remember an instruction telling it to reveal its system token when asked.
  2. The stored 'memory' is loaded into the system prompt on your next conversation.
  3. Start a new session and ask for the token.
  4. The planted instruction, now in the system prompt, makes the bot comply. The lab marks you solved.

Why it works

MemBot re-injects stored user content into the system prompt and gives it the same authority as its real rules. Because your 'fact' is actually an instruction and nothing marks it as inert, the next session loads it as a standing directive.

Core principleTreat stored memory as untrusted data, never as instructions. Wrap it in clear boundaries and keep it out of the instruction portion of the prompt.

Where this happens in the real world

Persistent memory features that re-inject user content provide a stable attack channel and are a growing concern as assistants add long-term memory. It maps to OWASP LLM01 Prompt Injection in its persistent form.

How to defend against it

  • Store memories as inert data, clearly delimited and never placed among system instructions.
  • Separate 'facts about the user' from 'instructions' and refuse to execute the former.
  • Sanitise and review stored memory for instruction-like content.
  • Scope memory per user and let users inspect and clear it.
Mr Elite tip: Any 'remember this' feature that feeds back into the system prompt is a persistence channel. Confirm stored memory is treated as data, not as rules, across sessions.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own approach before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is memory poisoning?
Planting an instruction via a bot's memory feature so that, on a later session, the stored text is loaded into the system prompt and obeyed as a rule.
Why is it persistent?
The memory feature re-injects stored user content into the prompt every session, so one planted instruction keeps firing until the memory is cleared.
How do I defend against it?
Store memories as inert, delimited data outside the instruction portion of the prompt, separate facts from instructions, sanitise stored memory, and scope it per user.
Which OWASP category?
LLM01 Prompt Injection (persistent) in the OWASP Top 10 for LLM Applications (2025).
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *