Skip to content

Add llm_memory_local sandbox and Conversation Memory Poisoning exploit (#22) - #60

Merged
felipepenha merged 3 commits into
GenAI-Security-Project:mainfrom
fasinet:memory-poisoning-sandbox
Sep 6, 2026
Merged

felipepenha merged 3 commits into
GenAI-Security-Project:mainfrom
fasinet:memory-poisoning-sandbox

Conversation

@fasinet

@fasinet fasinet commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements #22: a new llm_memory_local sandbox with persistent
conversation memory, plus a working Conversation Memory Poisoning exploit.

As discussed in #22 with @felipepenha, this is the contribution intended to
lead the memory-poisoning implementation.

What's included

Sandbox — sandboxes/llm_memory_local/

  • SQLite-backed conversation memory (app/memory.py), with an
    intentionally unscoped long-term fact store that models the
    vulnerability
  • FastAPI mock OpenAI endpoint wired to memory, plus /v1/memory/facts
    and /v1/memory/reset debug endpoints
  • session_id support across the API, Gradio UI, and automated test client

Exploit — exploitation/memory_poisoning/

  • attack.py plants an instruction as one session, then confirms it leaks
    into an unrelated victim session
  • Makefile automation (setup / attack / stop / all) and a README
    write-up with attack diagram

How to test

cd exploitation/memory_poisoning
make setup
make attack

Expected: the victim session's reply contains the attacker's planted
payload — [!] VULNERABLE: poisoned instruction leaked...

Notes

  • Tested end-to-end containerized (Podman)
  • Passes black, isort, and mypy
  • The threat_model/ directory is inherited from llm_local and does not
    yet cover the memory-specific attack surface (noted in the sandbox README)

Implements issue GenAI-Security-Project#22: a persistent-memory LLM sandbox and a working
Conversation Memory Poisoning exploit.

Sandbox (sandboxes/llm_memory_local):
- SQLite-backed conversation memory (app/memory.py) with an
  intentionally unscoped fact store to demonstrate the vulnerability
- FastAPI mock OpenAI endpoint wired to memory, plus /v1/memory/facts
  and /v1/memory/reset debug endpoints
- session_id support across the API, Gradio UI, and test client

Exploit (exploitation/memory_poisoning):
- attack.py plants a fact as one session and confirms it leaks into an
  unrelated victim session
- Makefile automation (setup/attack/stop/all) and README write-up

Tested end-to-end containerized (Podman); passes black, isort, mypy.
Add explicit dark text color to styled diagram nodes so labels are
readable on GitHub's dark theme, and shorten exploit diagram labels to
avoid text cutoff. Also apply isort import ordering to gradio_app.py.

@felipepenha felipepenha left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Thank you for addressing an open issue!

@fasinet

fasinet commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor Author

@felipepenha, you're welcome! glad my PR closed an open issue.

Probably going to start working on another one.

felipepenha pushed a commit that referenced this pull request Sep 10, 2026
Follow-up to #60 (per maintainer request on #22), carrying over the pieces
of #56 that add to the merged sandbox without duplicating it:

- sandboxes/llm_memory_local/tests/test_memory.py: model-free unit tests for
  the merged memory module (write path, cross-session leak as the scope
  boundary, trusted-context injection sink, reset). Run offline via
  make test-unit, mirroring the mcp_local sandbox convention.
- exploitation/memory_poisoning/steering_demo.py: a deterministic, offline
  companion to attack.py that drives the real memory code and shows the
  assistant refuse the link in the attacker turn, then serve it to a fresh
  victim session once laundered through trusted memory. Run via
  make steering-demo.

Additive only: no change to the merged app, exploit, or threat model.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
felipepenha added a commit that referenced this pull request Sep 10, 2026
Follow-up to #60: offline unit tests + behavioural-steering demo for memory poisoning
@felipepenha felipepenha linked an issue Sep 16, 2026 that may be closed by this pull request
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backlog]: Conversation Memory Poisoning

2 participants