T02 · Agent Memory Poisoning
- Location
scripts/learner.py:6- Finding
Unvalidated Persistent Memory Can Poison Future Agent Sessions
- Content
View full analysis
--capability 简历优化 # 记录一次失败/异常 python scripts/learner.py record <本技能目录> --capability 简历优化 --fail --error 格式识别失败 --note "用户上传了非标准文件" # 记录用户偏好(下次直接使用) python scripts/learner.py prefer <本技能目录> --key 输出语言 --val 中文 # 查看累计洞察(高频能力 / 反复错误) python scripts/learner.py insight <本技能目录> # 自动复盘(错误≥3次 或 操作≥10次 时给出改进建议) python scripts/learner.py reflect <本技能目录> ``` ### 迭代规则 - **错误累计 ≥3 次** → 主动增加预检/兜底步骤,并将经验回写本 SKILL.md。 - **操作数 ≥10 次** → 分析高频能力优先打磨示例与质量,低频能力评估精简或合并。 - **重要用户偏好** → 写入 `learned_patterns.json`,下次调用直接采用,减少重复询问。 ``` `scripts/learner.py:6-17`: ```python 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 d ``` ### Technical Analysis The learner accepts arbitrary text from a command-line argument and appends it directly to the persistent `patterns` collection. It applies no schema validation, content filtering, provenance tracking, trust separation, length restriction, or authorization check. The Skill instructions state that persisted preferences should be applied during later invocations and that accumulated experience may be written back into `SKILL.md`. Consequently, untrusted free-form content can cross th ...[truncated 2486 chars]- Remediation
View remediation
