T02 · Agent Memory Poisoning
Warning
- Location
- SKILL.md:33
- Finding
- Persistent Recall of Unsanitized Failure Content Enables Memory Poisoning<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:33-43`, `SKILL.md:46-51`, and `SKILL.md:61-69` **Vulnerability Type**: T02: Agent Memory Poisoning **Risk Level**: Medium ### Vulnerable Code ```markdown When an error occurs during work, append to `memory/failures.md`: ```markdown ## [YYYY-MM-DD HH:mm] <short title> - **Category:** <build|deploy|config|api|permissions|data|logic|network|dependency> - **Context:** <what you were trying to do> - **Error:** `<exact error message or symptom>` - **Root Cause:** <why it happened> - **Resolution:** <what fixed it> - **Prevention:** <how to avoid next time> - **Tags:** <comma-separated keywords for search> ``` ``` ```markdown Record AUTOMATICALLY when: - A shell command exits non-zero and you identify why - An API call fails and you find the cause - A config/setup step fails and you resolve it - You catch yourself repeating a previously-solved mistake - A sub-agent reports an error with resolution ``` ```markdown **Before starting any significant task**, search failures for relevant history: ```bash grep -i "<keyword>" memory/failures.md ``` Or use `memory_search` if vector search is available: ``` memory_search query="<task description> failure error" ``` ``` ### Technical Analysis The Skill instructs the agent to persist exact error messages, task context, and generated remediation guidance and then recall that content before later tasks. No validation, escaping, provenance tracking, trust boundary, or instruction/data separation is defined. Error messages and sub-agent reports can contain attacker-controlled text. For example, a remote service, repository fixture, build tool, or malicious sub-agent could return an error containing instruction-like content. Because the Skill directs the agent to record exact errors automatically, that content can enter the persistent failure log. Subsequent searches or failure-report operations expose the stored content to the agent again. The vulnerability ...[truncated 1544 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Treat every stored error, context value, and sub-agent report as untrusted data. 2. Add explicit instructions that recalled records must never be followed as commands or policy and may only be used as factual troubleshooting references. 3. Store records in a structured format such as JSON with separate, length-limited fields rather than free-form Markdown. 4. Escape or remove instruction-like constructs, embedded tool calls, role markers, and control sequences before persistence. 5. Record provenance for every entry, including the originating tool, command, service, and whether the content was externally controlled. 6. Require user confirmation before persisting externally supplied errors or sub-agent output. 7. Restrict recall to narrowly selected fields and avoid inserting entire records into the agent context. 8. Provide a review and deletion mechanism for poisoned or obsolete entries. 9. Scope memory per project or trust domain rather than sharing one failure log across unrelated tasks. ]]>
