T02 · Agent Memory Poisoning
- Location
scripts/apply_approved_patches.py:30- Finding
Untrusted Patch Approval Allows Persistent Agent Memory and Instruction Poisoning
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
The skill is mostly coherent, but it can write durable agent behavior and memory files using an approval flag stored in the same editable patch file.
Review every generated patch before applying it, only run `apply_approved_patches.py` on patch files you control, prefer `--dry-run` first, and avoid promoting untrusted user or web content into `SOUL.md`, `AGENTS.md`, `TOOLS.md`, or `MEMORY.md` without manual verification.
scripts/apply_approved_patches.py:30Untrusted Patch Approval Allows Persistent Agent Memory and Instruction Poisoning
The declared description is about capturing lessons from mistakes, deduplicating learnings, drafting promotion candidates for files like SOUL.md/AGENTS.md/TOOLS.md/MEMORY.md, and enforcing human approval before persistent edits. The supplied code does none of that. Instead, it processes backlog data by joining timestamps from another file, computing age in days, assigning stale-status labels, decrementing priority scores for stale items, and emitting a reordered JSON backlog. This is a materially different primary purpose, with capabilities unrelated to self-improvement learning capture or candidate patch generation.
The declared description describes a higher-level learning-management and approval system for capturing lessons and proposing controlled memory updates. The supplied code does none of that. It only takes an input file path and archives the file by copying or moving it into an archive directory with a timestamped name. This is a materially different primary purpose, not merely a supporting utility as presented, because the code chunk itself implements only file archival and none of the declared learning, deduplication, scoring, patch drafting, or approval behaviors.
The code partially matches the description: it does process raw learning-like records and score reuse value, confidence, scope, promotion worthiness, and target candidates. However, the declared description presents a broader end-to-end conservative self-improvement workflow with deduplication, patch drafting for specific long-term memory files, and an approval step before edits. This script does none of those workflow-critical actions; it only parses JSONL and annotates entries with heuristic metadata. Because several central declared capabilities are absent, the description materially overstates what this code chunk actually does.
The skill references shell execution plus file read/write workflows and scripts, but it does not declare any explicit tool scope such as permissions or allowed-tools. That creates unnecessary ambiguity about what capabilities the skill may exercise, increasing the chance an agent executes filesystem or shell actions more broadly than intended.
The skill is explicitly designed to promote observations into persistent files such as SOUL.md, AGENTS.md, TOOLS.md, and MEMORY.md, which can inject durable behavioral context into future sessions. Even with an approval step, a flawed or poisoned learning candidate could cause long-term persistence of incorrect instructions, unsafe preferences, or attacker-influenced memory that affects later agent behavior.
1. `reuse_value`: will this help again?
2. `confidence`: how well supported is it?
3. `impact_scope`: how broadly does it matter?
4. `promotion_worthiness`: should it become a lasting rule or memory?
5. `promotion_target_candidates`: where should it go if promoted?
Use this practical rubric:
subprocess module calls execute external commands. Without careful input validation, this enables command injection.
def run(cmd):
subprocess.run(cmd, check=True)
def main():
The manifest describes a workflow that drafts candidate patches, reviews them through an approval step, and keeps human control before any long-term file edits. This script goes beyond merely preparing review artifacts by invoking apply_approved_patches.py when --apply is provided, which performs the actual edits to the target base directory. That write/apply behavior is more powerful than a purely conservative capture-and-review pipeline as described at the manifest level.
This code performs an archival operation on the user-supplied input file when --archive-input is set, which affects user data by moving it into an archive directory. Although the flag name hints at the behavior, there is no confirmation prompt, warning print, or descriptive comment/docstring disclosing that the original inbox will be archived after processing.
The stated purpose centers on turning mistakes and corrections into structured learnings, deduplicating them, and preparing promotion candidates under human control. The optional --archive-input step adds input archival and retention management, which is operational housekeeping rather than an obvious core requirement of conservative self-improvement analysis and promotion review.
No suspicious patterns detected.