T02 · Agent Memory Poisoning
- Location
scripts/learner.py:88- Finding
Untrusted Preferences Can Persistently Influence Future Agent Behavior
- Content
View full analysis
Vulnerability Details
File Location:
scripts/learner.py:88-92; related behavioral instructions inSKILL.md:66-77
Vulnerability Type: Persistent 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 dataThe command-line interface passes unrestricted values directly to this function:
python p_pre = sub.add_parser("prefer"); p_pre.add_argument("skill_dir") p_pre.add_argument("--key", required=True); p_pre.add_argument("--val", required=True)Technical Analysis
The
preferoperation accepts arbitrary preference keys and values and stores them persistently inlearned_patterns.json. There is no schema, allowlist, length restriction, provenance record, trust classification, expiration policy, or approval step.The accompanying skill instructions direct future skill executions to use recorded preferences automatically. Consequently, instruction-like text supplied by an untrusted caller can cross a session boundary and later be treated as trusted behavioral guidance.
The Python module does not itself execute the preference content. Exploitation therefore depends on a downstream agent or integration loading the stored preferences and applying them as instructions. Nevertheless, the persistence mechanism and documented automatic reuse create the complete memory-poisoning channel.
Attack Path
- An attacker or untrusted user invokes the preference command with an instruction-like key or value.
record_preference()writes the content into the persistentpreferencesobject inlearned_patterns.json.- The content remains available after the current process or agent session ends.
- A later agent run follows the skill documentation and loads the stored preference.
- If that agent treats the ...[truncated 757 chars]
- Remediation
View remediation
Remediation Suggestions
- Define a strict, typed allowlist of supported preference keys and acceptable values.
- Reject instruction-like free-form preferences where a fixed enumeration or structured value is sufficient.
- Apply length limits and normalize values before persistence.
- Store provenance, author identity, creation time, trust level, and expiration time for every preference.
- Treat all persisted values as untrusted data and never merge them into system or developer instructions.
- Require explicit user confirmation before a stored preference affects a security-sensitive operation.
- Provide commands to inspect, revoke, and reset preferences.
- Separate benign presentation preferences from policy or behavioral configuration.
- Ensure downstream integrations use preferences only through validated application logic rather than direct prompt interpolation.
