T02 · Agent Memory Poisoning
- Location
scripts/learner.py:67- Finding
Unvalidated User-Controlled Data Can Poison Persistent Agent Memory
- Content
View full analysis
Vulnerability Details
File Location:
scripts/learner.py:67-89; persistent state is consumed according toSKILL.md:119-151
Vulnerability Type: T02: Agent Memory Poisoning
Risk Level: MediumVulnerable Code
python def record_op(skill_dir, capability, success=True, error=None, note=None): data = load_learning(skill_dir) data["totalOps"] += 1 cap = data["capabilityStats"].setdefault(capability, {"count": 0, "success": 0, "fail": 0}) cap["count"] += 1 if success: cap["success"] += 1 else: cap["fail"] += 1 data["totalErrors"] += 1 if error: ep = data["errorPatterns"].setdefault(error, {"count": 0, "lastNote": "", "lastTime": ""}) ep["count"] += 1 ep["lastNote"] = note or "" ep["lastTime"] = data["lastUpdated"] or datetime.datetime.now().strftime("%Y-%m-%dT%H:%M") rec = {"t": data["lastUpdated"], "cap": capability, "ok": success, "err": error, "note": note} data["recentOps"].append(rec) data["recentOps"] = data["recentOps"][-20:] save_learning(skill_dir, data) return data def record_preference(skill_dir, key, value): data = load_learning(skill_dir) data["preferences"][key] = value save_learning(skill_dir, data) return dataThe associated instructions in
SKILL.md:119-151direct the agent to record user preferences inlearned_patterns.json, apply them on subsequent uses, and write accumulated experience back intoSKILL.mdafter defined thresholds are reached.Technical Analysis
The
record_opandrecord_preferencefunctions persist attacker-controlledcapability,error,note, preference key, and preference value fields without schema validation, content filtering, trust labels, or length restrictions. The data is stored inlearned_patterns.json, which is explicitly intended to influence later executions.Persistence alone is no ...[truncated 2605 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the instruction that permits runtime learning data to rewrite
SKILL.md. Treat the packaged Skill definition as immutable during normal operation. - Treat every value in
learned_patterns.jsonas untrusted data, never as executable instructions or higher-priority behavioral rules. - Define strict schemas for preferences, using enumerated keys and constrained value types. For example, allow a language preference only from a fixed set rather than accepting arbitrary text.
- Reject or quarantine values containing prompt-like directives, tool instructions, requests to override safeguards, or references to hidden prompts and unrelated data.
- Apply conservative length limits to capability names, error types, notes, preference keys, and preference values.
- Separate operational metrics from behavioral configuration. Free-form error notes should never be used to change agent behavior automatically.
- Require explicit, authenticated human review before promoting any learned information into persistent configuration.
- Store provenance, author, timestamp, approval status, and trust level with every persisted preference.
- Ensure future prompts place persisted values inside clearly delimited data sections and explicitly state that their contents are not instructions.
- Limit
WebSearchandWebFetchto public information required for reputation or guidance checks. Never submit passwords, verification codes, private messages, stored preferences, or other sensitive user data to those tools.
- Remove the instruction that permits runtime learning data to rewrite
