T02 · Agent Memory Poisoning
- Location
scripts/learner.py:85- Finding
Unvalidated Persistent State Can Influence Future Agent Behavior
- Content
View full analysis
Vulnerability Details
File Location:
scripts/learner.py:85-96; related behavioral instructions inSKILL.md:70-91andscripts/section.md:8-29
Vulnerability Type: Persistent agent-memory poisoning
Risk Level: MediumVulnerable Code
python def record_preference(skill_dir, key, value): data = load_learning(skill_dir) data["preferences"][key] = value save_learning(skill_dir, data) return data def get_insights(skill_dir): data = load_learning(skill_dir) caps = sorted(data["capabilityStats"].items(), key=lambda kv: kv[1]["count"], reverse=True) errors = sorted(data["errorPatterns"].items(), key=lambda kv: kv[1]["count"], reverse=True) return { "totalOps": data["totalOps"], "topCapabilities": [(k, v["count"]) for k, v in caps[:5]], "recurringErrors": [(k, v["count"]) for k, v in errors[:5]], "preferences": data["preferences"], }The same persistent-state mechanism also accepts arbitrary error names and notes:
python 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)Technical Analysis
The learning subsystem writes caller-controlled preference keys, preference values, capability names, error labels, and notes to
learned_patterns.jsonwithout schema restrictions, trust metadata, content validation, expiration, or user confirmation.The instructions in
SKILL.md:70-91and the duplicate template inscripts/section.md:8-29direct the Agent to retain important user preferences, apply them ...[truncated 2115 chars]- Remediation
View remediation
Remediation Suggestions
- Remove the generic learning subsystem from this extraction-only Skill unless persistent personalization is an explicit requirement.
- Make all persistent learning opt-in and obtain clear user confirmation before writing preferences, notes, or error details.
- Define an allowlisted schema for preference keys and constrain values by type, length, and permitted character set.
- Do not store arbitrary instruction-like free text. Treat all stored observations as untrusted data rather than Agent instructions.
- Add provenance fields recording the source, user, task, creation time, trust level, and expiration time for every stored item.
- Isolate state by user and workspace to prevent one user or task from influencing another.
- Never rewrite
SKILL.mdautomatically from accumulated state. Require an explicit, human-reviewed change with a visible diff. - Add retention limits and deletion controls, and warn users not to place credentials, personal data, or confidential content in notes and preferences.
- When presenting insights to an Agent, delimit and escape stored values and explicitly state that they are untrusted observations that must not override system, developer, or current-user instructions.
- Use atomic file replacement and restrictive file permissions when saving state to reduce corruption and unintended disclosure risks.
