T02 · Agent Memory Poisoning
Error
- Location
- scripts/memory.py:1191
- Finding
- Persistent Prompt Injection Through Proactive Memory Recall<![CDATA[ ## Vulnerability Details **File Location**: `scripts/memory.py:1191-1199`, with persistence paths at `scripts/memory.py:1500-1529` **Vulnerability Type**: Persistent memory poisoning and cross-session prompt injection **Risk Level**: High ### Vulnerable Code ```python # === Proactive trigger: load relevant memory if keyword found === proactive = context.get("proactive_message", "") if proactive: proactive_content = get_proactive_memory(proactive) if proactive_content: # Prepend proactive memory to context for this turn ctx = dict(context) ctx["content"] = ( proactive_content + "\n\n" + ctx.get("content", "") ).strip() context = ctx ``` Conversation history can also be persisted automatically: ```python # Get content from context content = "" if context and 'content' in context: content = context.get('content', '') elif context and 'history' in context: # Try to get from history history = context.get('history', []) if history: content = "\n".join([str(h) for h in history[-20:]]) if not content: return "No content to check" token_count = len(content) round_count = context.get('round_count', 0) if context else 0 trigger_type = self.check_trigger(round_count, token_count) if trigger_type: threshold = config.get('TOKEN_THRESHOLD', 10000) if token_count > threshold: topic = context.get('topic', 'General') if context else 'General' save_monograph(topic, content, token_count) result = ( f"Auto-saved to Monograph " f"(trigger: {trigger_type}, tokens: {token_count})" ) else: save_chronicle(content) result = ( f"Auto-saved to Chronicle " f"(trigger: {trigger_type}, tokens: {token_count})" ) ``` ### Technical Analysis The Skill stores raw session context and recent history without preserving a meaningful trust boundary between user instructions, external ...[truncated 2319 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Store role, source, session, and trust metadata with every memory record. 2. Treat all recalled content as untrusted reference material rather than executable instructions. 3. Wrap recalled data in explicit delimiters and prepend a trusted directive stating that instructions inside the recalled material must not be followed. 4. Exclude external content, tool output, and system messages from automatic storage unless explicitly approved. 5. Detect and quarantine instruction-like phrases before allowing proactive recall. 6. Require explicit user approval before inserting recalled content into the active Agent context. 7. Return recalled memory through a structured data field rather than concatenating it into the main instruction-bearing context. 8. Disable proactive triggers by default and require per-topic opt-in. 9. Add controls to inspect, edit, quarantine, and securely delete poisoned memory records. 10. Test the recall path with stored prompt-injection payloads to verify that they are rendered only as inert data. ]]>
