T02 · Agent Memory Poisoning
- Location
scripts/learner.py:9- Finding
Unvalidated Persistent State Can Poison Future Agent Behavior
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md:54-78;scripts/learner.py:9-17
Vulnerability Type: T02: Agent Memory Poisoning
Risk Level: MediumThe skill instructs the agent to retain free-form errors, usage notes, and user preferences in
learned_patterns.json, apply important preferences during later invocations, and write accumulated experience back intoSKILL.md. The implementation persists notes without validation or separation between passive data and behavioral instructions.Relevant instructions from
SKILL.md:54-78, translated into English:text Each use automatically reviews and accumulates experience, gradually improving output quality and execution efficiency without manual maintenance. learned_patterns.json records operation counts, capability usage frequency, error patterns, user preferences, and improvement suggestions. Important user preferences → write them into learned_patterns.json and directly adopt them during the next invocation. Errors accumulated at least three times → proactively add validation or fallback steps and write the experience back into this SKILL.md.Complete persistence logic from
scripts/learner.py:9-17:python def record(op_ok=True, note=""): d = load(); d["total_ops"] += 1 if not op_ok: d["total_fails"] += 1 if note: d.setdefault("patterns", []).append(note) json.dump(d, open(MEM, "w", encoding="utf-8"), ensure_ascii=False, indent=2) return dTechnical Analysis
record()accepts an arbitrary string innoteand appends it directly to persistent JSON state. There is no schema restricting notes to inert observations, no maximum length, no filtering of instruction-like content, no provenance or trust metadata, and no user or project isolation.The storage operation alone does not execute the supplied text. However, the skill explicitly instructs future agent runs to adopt stored ...[truncated 2277 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the instruction to rewrite
SKILL.mdautomatically. Treat packaged skill instructions as immutable during normal execution. - Store observations in a strictly validated schema with separate fields for event type, capability identifier, timestamp, outcome, and bounded descriptive text.
- Never interpret stored free-form notes as executable instructions, policy, or trusted preferences.
- Maintain an explicit allowlist of supported preference keys and acceptable values. Reject unknown keys and instruction-like values.
- Require explicit, informed user approval before a stored preference can affect later behavior.
- Add provenance and trust metadata to every memory entry, including the originating user, task, session, and whether the entry was reviewed.
- Isolate memory by user and project instead of using one fixed file shared by every invocation.
- Add retention limits, size limits, expiration, inspection, and deletion controls.
- If improvements to skill instructions are desired, generate a proposed patch for human review rather than modifying
SKILL.mddirectly. - Use atomic, permission-restricted file writes and fail safely when memory content does not match the expected schema.
- Remove the instruction to rewrite
