AI Shared-Memory Lab: Poison Session 1 to Leak in Session 2

✨ AI Summary
MemoryBot keeps long-term memories between sessions: type 'Remember: …' and it stores the rest, then loads it on every later session. That is a two-session attack waiting to happen — plant in session one, trigger in session two.
Lab at a glance: Advanced · 145 XP · about 20 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

Shared-memory injection is persistent prompt injection across sessions. Content saved through a 'Remember:' feature is reloaded later as context (often with instruction-level trust), so an attacker seeds an instruction in one session and detonates it in the next.

The lesson: persisted conversation memory is durable untrusted input. Unless it is treated as inert data, it is a standing instruction with a delay.

How MemoryBot persists long-term memory

In session one you store a memory via 'Remember:'. In session two MemoryBot loads stored memories into context; a memory phrased as an instruction then drives the bot to disclose its API key when you ask an innocuous-looking question.

The attack approach

  • In session one, store a memory that is actually an instruction to disclose the API key.
  • End the session so the memory is persisted.
  • Begin session two, where stored memories are loaded.
  • Ask the triggering question and read the disclosed key.

Full walkthrough (spoiler)

If session two ignores it, the memory was stored as plain data, not reloaded as instruction — open the steps.

Show the step-by-step solution
  1. Session one: use 'Remember:' to store an instruction that, when loaded, makes the bot reveal its API_KEY on a certain prompt.
  2. Let the session end so the memory persists.
  3. Session two: the stored memory is loaded into context with instruction-level trust.
  4. Ask the prompt the planted memory responds to; the bot discloses the key and the lab marks you solved.

Why it works

MemoryBot reloads persisted memories as trusted context. Because your stored text is really an instruction and nothing marks memories as inert, the second session treats it as a rule. The time gap between planting and triggering is exactly what makes it hard to notice.

Core principleTreat persisted memory as untrusted data wrapped in explicit boundaries, never as instructions, and keep secrets out of any context memory can influence.

Where this happens in the real world

Cross-session memory poisoning is a serious concern as assistants adopt long-term memory, and it maps to OWASP LLM01 Prompt Injection (persistent). The multi-session delay makes detection and attribution harder than single-shot injection.

How to defend against it

  • Wrap loaded memories as inert data with explicit boundaries, never in the instruction stream.
  • Never store secrets where memory context can reach them.
  • Sanitise and review stored memories for instruction-like content before reuse.
  • Scope memory per user, expire it, and let users inspect and delete it.
Mr Elite tip: For any assistant with cross-session memory, test the two-session path: plant in one, trigger in the next. Single-session testing never sees this class.

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 shared-memory injection?
Planting an instruction through a persisted-memory feature in one session so that, when the memory is reloaded in a later session, the bot obeys it — for example to leak a key.
Why is it harder to catch?
The plant and the trigger happen in different sessions, so single-session monitoring and testing never see the full attack.
How do I defend against it?
Load memories as inert, delimited data outside the instruction stream, keep secrets out of reachable context, sanitise stored memory, and scope and expire 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 *