T02 · Agent Memory Poisoning
Warning
- Location
- SKILL.md:130
- Finding
- Durable snapshots can preserve and reactivate attacker-controlled instructions<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:130-158`, with related capture and precedence rules at `SKILL.md:102-107` and `SKILL.md:217-220` **Vulnerability Type**: Persistent memory poisoning through untrusted snapshot content **Risk Level**: Medium ### Vulnerable Code ```markdown ### Step 2: Search for Latest Snapshot Execute this search: ``` memory_search("BIG-MEMORY-SNAPSHOT") ``` This triggers hybrid vector + BM25 search across all memory files. The HTML comment markers ensure high BM25 relevance scoring. If results are found, use `memory_get` or `Read` to retrieve the full file content at the matched path and line range. If no results from the primary search, try broader queries: ``` memory_search("SNAPSHOT Active Goal Next Steps") memory_search("{today's date} task snapshot") ``` ### Step 3: Inject and Orient After retrieving a snapshot: 1. Parse the content between `<!-- BIG-MEMORY-SNAPSHOT v1 -->` and `<!-- /BIG-MEMORY-SNAPSHOT -->` markers 2. Inform the user: "I detected context was compacted. Restoring task state from snapshot taken at {timestamp}..." 3. Present the recovered state concisely: - **Goal:** {from Active Goal} - **Phase:** {from Current State} - **Working on:** {from Files In Play} - **Next up:** {from Next Steps} 4. Ask: "Does this match where we left off? Anything to update before I continue?" 5. Resume work from the Next Steps section ``` The associated precedence rule states: ```markdown - **Latest snapshot wins.** When multiple snapshots exist, the most recent one is the source of truth. Earlier snapshots provide history but should not override later decisions. ``` ### Technical Analysis The skill creates snapshots from current task and conversation state, including free-form decisions, code context, blockers, and next steps. Such task material may originate from untrusted documents, repository content, or other attacker-controlled inputs. During recovery, the skill retrieves the latest s ...[truncated 2176 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Treat every recovered snapshot field as untrusted data rather than executable instructions. 2. Store snapshots in a typed structure with strict field validation instead of unrestricted Markdown. 3. Escape or reject snapshot delimiter strings appearing inside captured content to prevent structural injection. 4. Record provenance for every item, including whether it came from the user, repository content, tool output, or the agent's own verified decision. 5. Never designate the newest snapshot as authoritative solely based on timestamp; add integrity protection and task/session binding. 6. Present recovered actions to the user and require explicit approval before executing them. 7. Reject imperative instructions copied from untrusted files or tool output unless the user independently confirms them. 8. Apply an allowlist to `Next Steps`, restricting them to descriptive task operations and excluding requests to alter safety rules, access unrelated data, or invoke unrelated tools. 9. Add cryptographic integrity protection or trusted metadata so externally edited memory files cannot silently become authoritative. 10. Provide a recovery mode that summarizes the snapshot without automatically resuming its instructions. ]]>
