T02 · Agent Memory Poisoning
- Location
src/mindclaw/store.py:748- Finding
Persistent Prompt Injection Through Unsanitized Memory Content
- Content
View full analysis
int: # ... for line in text.splitlines(): stripped = line.strip() # Category headings if stripped.startswith("#"): heading = stripped.lstrip("#").strip().lower() current_category = next( (cat for key, cat in cat_map.items() if key in heading), "note", ) continue # Bullet points → memories if stripped.startswith(("- ", "* ", "+ ")): content = stripped[2:].strip() if len(content) < 5: continue tags = _re.findall(r"`([^`]+)`", content) content_clean = _re.sub(r"\s*`[^`]+`", "", content).strip(" 📌").strip() if not content_clean or content_clean.lower() in seen: continue m = Memory( content=content_clean, category=current_category, tags=tags, source=source or str(target), agent_id=agent_id, created_at=file_date or time.time(), ) self.add(m) ``` The imported content is later rendered directly into an LLM context block: ```python HEADER = "## Relevant memories\n" FOOTER = "\n## End of memories\n" MEMORY_TEMPLATE = ( "[{id}] ({category}, importance={importance:.2f}{pinned_marker}) {content}" ) # ... line = self.MEMORY_TEMPLATE.format( id=mem.id, category=mem.category, importance=mem.importance, pinned_marker=pinned_marker + conf_marker, content=mem.content, ) # ... def build_system_prom ...[truncated 2472 chars]- Remediation
View remediation
