T02 · Agent Memory Poisoning
- Location
scripts/learner.py:6- Finding
Unvalidated Notes Persisted as Cross-Session Agent State
- Content
View full analysis
Vulnerability Details
File Location:
scripts/learner.py:6-16; persistence directives inSKILL.md:27-31
Vulnerability Type: Persistent agent memory poisoning
Risk Level: MediumThe skill documentation directs the agent to record failure patterns in a learner and use them for cross-session evolution. The implementation accepts an arbitrary note from the command line and stores it persistently without validation, provenance tracking, size limits, or separation between untrusted observations and trusted instructions.
Complete Vulnerable Code
python MEM = os.path.join(os.path.dirname(__file__), "learned_patterns.json") def load(): try: return json.load(open(MEM, encoding="utf-8")) except Exception: return {"total_ops": 0, "total_fails": 0, "patterns": []} 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 dThe externally supplied command-line value is passed directly to the persistent recorder:
python if __name__ == "__main__": ok = (sys.argv[1] != "fail") if len(sys.argv) > 1 else True rec = (sys.argv[2] if len(sys.argv) > 2 else "") print(json.dumps(record(ok, rec), ensure_ascii=False))Technical Analysis
record()appends thenotevalue unchanged to the persistentpatternsarray inscripts/learned_patterns.json. The note can contain arbitrary text and is not subject to schema validation, length restrictions, trust labeling, sanitization, or user approval.This behavior is security-relevant because
SKILL.md:27-31describes the stored material as input to reflection, learner, and meta-evolution workflows intended to affect future sessions. If a downstream agent or meta-evolver interprets stored ...[truncated 1870 chars]- Remediation
View remediation
Remediation Suggestions
- Remove mandatory cross-session learning from the attribution skill unless persistent state is necessary and explicitly approved by the user.
- Replace free-form notes with a strict structured schema containing allowlisted fields, such as an operation identifier, a bounded error code, and numeric outcome metrics.
- Enforce maximum lengths, entry counts, and total file size. Reject malformed or oversized records.
- Attach provenance and trust metadata to every record, distinguishing untrusted task content from administrator-approved guidance.
- Never insert stored notes directly into an agent system prompt or treat them as executable instructions. Render them as quoted, untrusted data and apply an explicit review or approval step before they can affect behavior.
- Store state outside the skill source directory in a permission-restricted application data location, and use atomic file replacement and file locking to prevent corruption.
- Define retention and deletion controls so users can inspect, clear, or disable persistent learning.
- If only operational telemetry is required, store aggregate counters and remove the arbitrary
patternstext field entirely.
