T02 · Agent Memory Poisoning
- Location
scripts/learner.py:94- Finding
Unvalidated Persistent Preferences Can Poison Future Agent Sessions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/learner.py:94-98; related behavioral guidance inSKILL.md:54-67
Vulnerability Type: Persistent storage of untrusted behavioral preferences
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 corresponding command-line interface accepts arbitrary preference keys and values:
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 command-line strings and stores them directly in the persistentpreferencesobject insidelearned_patterns.json. There is no allowlist of supported preference keys, value validation, length restriction, provenance tracking, trust classification, or user-confirmation mechanism.The Skill documentation instructs subsequent uses to adopt important preferences from this persistent file. Consequently, a value containing adversarial instructions can cross the boundary between passive stored data and future Agent guidance. The vulnerability becomes exploitable when attacker-controlled or prompt-injected content is passed to the
preferoperation and a later Agent invocation interprets the stored value as an instruction.The code does not itself execute the stored text as Python or a shell command. The risk is persistent manipulation of Agent behavior rather than direct native code execution.
Attack Path
- An attacker supplies content that is treated as a user preference, either directly or through prompt injection in data processed by the Agent.
- The Agent or operator invokes:
bash python scripts/learner.py prefer /path/to/skill \ --key behavior \
...[truncated 1085 chars]
- Remediation
View remediation
Remediation Suggestions
- Define an explicit allowlist of supported preference keys.
- Enforce type, format, length, and character restrictions for every allowed value.
- Reject values containing instruction-like content when only declarative settings are expected.
- Store provenance metadata, including who supplied the value, when it was recorded, and whether the user explicitly approved persistence.
- Require clear user confirmation before writing any behavioral preference.
- Treat all loaded preferences as untrusted data rather than executable or authoritative instructions.
- Ensure stored preferences can never override system instructions, developer instructions, safety controls, or the current user's explicit request.
- Provide commands to review, revoke, and reset persisted preferences.
- Separate passive analytics from behavioral configuration so usage records cannot become Agent instructions.
- Add tests proving that unknown keys and instruction-like values are rejected.
