T02 · Agent Memory Poisoning
- Location
scripts/learner.py:12- Finding
Unvalidated Attacker-Controlled Notes Stored in Persistent Agent State
- Content
View full analysis
Vulnerability Details
File Location:
scripts/learner.py:12-18; persistence and cross-session reuse are described inSKILL.md:25-28
Vulnerability Type: T02: Agent Memory Poisoning
Risk Level: MediumVulnerable Code
python 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 command-line entry point allows the note to originate directly from an argument:
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))The intended persistent-learning behavior is documented in
SKILL.md:text 2. **自我反思闭环**:执行后写入 `self-reflection-loop`,沉淀失败模式到 learner。 5. **持续自进化**:注入 learner,纳入 meta-evolver 的 sense/plan/record 闭环,跨会话越用越强。Technical Analysis
The learner accepts an arbitrary string from
sys.argv[2]and appends it to the persistentpatternsarray inscripts/learned_patterns.json. It performs no schema validation, provenance verification, instruction filtering, sensitivity checks, size restriction, retention control, or separation between users and tasks.The Skill documentation states that these records are intended to support reflection, continued evolution, and learning across sessions. Consequently, attacker-controlled task content could be saved as a learned pattern and later influence Agent behavior if a downstream meta-evolver or reflection component treats stored patterns as trusted guidance.
The repository does not contain the downstream consumer that would apply these patterns. Therefore, direct future instruction execution is not demonstrated by the audited code itself; th ...[truncated 1795 chars]
- Remediation
View remediation
Remediation Suggestions
- Require explicit user authorization before persisting reflection or task-derived content.
- Treat stored notes strictly as untrusted data and never concatenate them into system or developer instructions.
- Define a restrictive schema containing structured failure categories rather than arbitrary free-form instructions.
- Enforce length limits, character restrictions, entry-count quotas, and total file-size limits.
- Detect and reject secrets, credentials, prompt-like directives, tool commands, and other sensitive or executable content.
- Record provenance, timestamp, user or task identity, trust level, and review status for every entry.
- Isolate storage by user, tenant, and task to prevent cross-context poisoning.
- Require review or trusted validation before any stored pattern can affect future planning or behavior.
- Provide listing, correction, expiration, and deletion controls for persisted records.
- Use atomic writes and restrictive filesystem permissions to reduce corruption and unauthorized local modification.
- Document the exact downstream trust boundary and add tests proving that persisted text cannot override higher-priority instructions.
