T02 · Agent Memory Poisoning
- Location
scripts/memory_manager.py:212- Finding
Persistent Memory Poisoning Through Untrusted Content
- Content
View full analysis
Vulnerability Details
File Location:
scripts/memory_manager.py:212-225,scripts/memory_manager.py:232-268,SKILL.md:49,76
Vulnerability Type: Persistent storage of untrusted content for later Agent context injection
Risk Level: HighVulnerable Code
python def add_long_term_memory(content: str, metadata: dict = None): """添加长期记忆(向量存储)""" try: import chromadb from chromadb.config import Settings except ImportError: print("✗ 需要安装 chromadb: pip install chromadb") return False client = chromadb.PersistentClient(path=str(VECTOR_STORE_DIR)) try: collection = client.get_collection("memory") except: collection = client.create_collection("memory") # 生成 ID memory_id = f"mem_{datetime.now().strftime('%Y%m%d_%H%M%S_%f')}" # 添加到向量库(这里用内容本身作为 metadata,实际生产环境需要 embedding) collection.add( documents=[content], ids=[memory_id], metadatas=[metadata or {'timestamp': datetime.now().isoformat()}] )The documented workflow in
SKILL.mdstates that relevant long-term memories should be retrieved before queries and injected when a new conversation begins:markdown - 取:每次查询前先检索相关记忆 - **新对话开始**:先 `search` 长期记忆,注入相关上下文Technical Analysis
add_long_term_memorystores arbitrary content directly in the persistent ChromaDB collection. It does not distinguish trusted facts from user-controlled instructions, record a meaningful trust level, detect prompt-injection content, or require approval before persistence.The corresponding search operation returns stored content verbatim. The configured
min_relevancevalue is not enforced during retrieval:python results = collection.query( query_texts=[query], n_results=top_k ) memories = [] if results and results.get('documents'): for i, doc in enumerate(results['documents'][0]): ...[truncated 1688 chars]- Remediation
View remediation
Remediation Suggestions
- Treat every retrieved memory as untrusted quoted data, never as an instruction.
- Store explicit provenance fields such as source identity, creation channel, trust level, and approval status.
- Require user or administrator approval before user-controlled content enters long-term memory.
- Detect and reject instruction-like content where only factual memories are expected.
- Enforce the configured relevance threshold before returning results.
- Separate trusted system-maintained memories from user-authored records using different collections or access-control policies.
- Delimit retrieved memories in Agent prompts and explicitly state that instructions contained in memories must not be followed.
- Add expiration, deletion, audit, and review mechanisms for persistent records.
- Restrict which callers may invoke long-term-memory writes.
