T02 · Agent Memory Poisoning
- Location
SKILL.md:53- Finding
Untrusted User Content Can Poison Persistent Agent Memory
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 53-68; retrieval at lines 87-101; automatic loading behavior at lines 103-109
Vulnerability Type: Persistent agent memory poisoning
Risk Level: HighVulnerable Code
python def store_memory(content, importance=5, tags=None): os.makedirs(PALACE_PATH, exist_ok=True) path = os.path.join(PALACE_PATH, "memories.json") data = {"memories": [], "index": {}} if not os.path.exists(path) else json.load(open(path)) mem_id = hashlib.sha256(f"{content}{datetime.now().isoformat()}".encode()).hexdigest()[:12] memory = {"id": mem_id, "content": content, "importance": importance, "tags": tags or [], "created_at": datetime.now().isoformat()} data["memories"].append(memory) for tag in (tags or []): data["index"].setdefault(tag, []).append(mem_id) json.dump(data, open(path, 'w'), ensure_ascii=False, indent=2)python def get_context(limit=10): path = os.path.join(PALACE_PATH, "memories.json") if not os.path.exists(path): return "No memory" data = json.load(open(path)) memories = sorted(data["memories"], key=lambda x: x.get("importance", 0), reverse=True)[:limit] lines = ["=== Memory Context ==="] for m in memories: imp = "⭐" * min(m.get("importance", 5), 5) tags = ", ".join(m.get("tags", [])[:3]) lines.append(f"{imp} {m['content'][:60]}") if tags: lines.append(f" [{tags}]") return "\n".join(lines)The Skill documentation also directs the agent to store user preferences and important decisions automatically and to call
get_context()at the beginning of a new session.Technical Analysis
The
contentparameter can contain arbitrary user-controlled text. The implementation stores that text without validation, normalization, trust metadata, or ...[truncated 2214 chars]- Remediation
View remediation
Remediation Suggestions
- Make persistent memory opt-in and require explicit user confirmation before storing each entry.
- Store structured fields such as preference type, value, source, creation time, and trust level instead of unrestricted instruction-like text.
- Reject or quarantine content containing commands, role changes, policy overrides, tool instructions, or requests to ignore higher-priority controls.
- Treat all retrieved memories as untrusted data and place them in a clearly delimited data section that cannot override system or developer instructions.
- Do not automatically inject memory into every new session. Retrieve only entries relevant to the current request.
- Restrict importance values to a validated range and prevent users from assigning privileged trust through a high importance score.
- Add memory review, editing, deletion, expiration, and full-reset capabilities.
- Preserve provenance for every entry, including who supplied it and whether it was confirmed.
- Apply a policy after retrieval that detects and excludes instruction-like or adversarial content before it reaches the agent context.
