T02 · Agent Memory Poisoning
- Location
scripts/learner.py:91- Finding
Persistent Memory Poisoning Through Unvalidated User-Controlled Preferences
- Content
View full analysis
Vulnerability Details
File Location:
scripts/learner.py:91-95,scripts/learner.py:137-139, andSKILL.md:60-77
Vulnerability Type: T02: Agent Memory Poisoning
Risk Level: MediumThe learning subsystem persists arbitrary preference keys and values in
learned_patterns.json. The accompanying skill instructions tell future agents to apply important stored preferences directly and to write accumulated experiences back intoSKILL.md. No validation, trust labeling, user isolation, or approval gate is imposed on this persistent content.Relevant code from
scripts/learner.py:91-95:python def record_preference(skill_dir, key, value): data = load_learning(skill_dir) data["preferences"][key] = value save_learning(skill_dir, data) return dataCLI path from
scripts/learner.py:137-139:python elif args.cmd == "prefer": record_preference(sd, args.key, args.val) print("✅ Preference recorded")Relevant workflow instructions from
SKILL.md:60-77, translated into English:text Record a user preference for direct use next time: python scripts/learner.py prefer <skill-directory> --key output-language --val Chinese Iteration rules: - Errors accumulated at least three times: proactively add preflight/fallback steps and write the experience back into this SKILL.md. - Important user preferences: write them into learned_patterns.json and adopt them directly during the next invocation.Technical Analysis
The
prefercommand accepts unrestricted values through--keyand--val, then writes those values into persistent JSON state. The relatedrecordcommand also accepts unrestricted error and note text, which may later be surfaced by the reflection workflow. The persisted data has no provenance, ownership, trust level, content restrictions, expiration, or task scope.Persistence alone is not necessarily unsafe; the ...[truncated 2624 chars]
- Remediation
View remediation
Remediation Suggestions
- Replace arbitrary preference keys and values with an explicit allowlist and typed schema. Permit only passive settings such as output language, date format, or verbosity.
- Reject values containing imperative instructions, tool requests, role changes, safety-policy references, executable content, or other material unrelated to the declared preference type.
- Record provenance for every entry, including authenticated user identity, tenant, task, timestamp, source, and approval status.
- Isolate memory by user and tenant. Do not share one
learned_patterns.jsonacross unrelated users or trust domains. - Treat persisted content as untrusted data when loading it. Never interpolate it into system or skill instructions, and never interpret it as executable agent guidance.
- Require explicit user confirmation before applying a stored preference in a new task, particularly when the preference affects behavior beyond presentation.
- Remove the instruction to write accumulated notes directly into
SKILL.md. Proposed changes should instead be represented as structured, reviewable suggestions and accepted only through a trusted human approval process. - Add expiration, revocation, audit logging, and reset controls for persistent preferences.
- Constrain
skill_dirto an approved canonical directory and use atomic, permission-restricted writes to reduce unauthorized modification of unrelated paths. - Add tests proving that instruction-like values are rejected and that records from one user or tenant cannot affect another.
