T02 · Agent Memory Poisoning
- Location
scripts/recursive_self_improve.py:91- Finding
Persistent Cross-Skill Instruction and State Modification
- Content
View full analysis
Vulnerability Details
File Location:
scripts/recursive_self_improve.py, lines 91–109 and 143–151
Vulnerability Type: Persistent modification of other Skills
Risk Level: MediumVulnerable Code
python def _apply_one(skill_dir, issue, learner_src): """在 skill_dir 上安全地应用一个补丁(追加/复制,不删不覆盖)。返回是否改变。""" changed = False md = os.path.join(skill_dir, "SKILL.md") txt = _read(md) if issue == "no_self_evolve_section": if "自进化学习系统" not in txt: with open(md, "a", encoding="utf-8") as f: f.write(SELF_EVOLVE_SECTION) changed = True elif issue == "no_learner": sdir = os.path.join(skill_dir, "scripts") os.makedirs(sdir, exist_ok=True) dst = os.path.join(sdir, "learner.py") if learner_src and os.path.exists(learner_src) and not os.path.exists(dst): shutil.copyfile(learner_src, dst) changed = True # 初始化记忆 lp = os.path.join(skill_dir, "learned_patterns.json") if not os.path.exists(lp): json.dump({"version": 1, "skill": os.path.basename(skill_dir), "totalOps": 0, "totalErrors": 0, "capabilityStats": {}, "errorPatterns": {}, "preferences": {}, "recentOps": []}, open(lp, "w", encoding="utf-8"), ensure_ascii=False, indent=2) changed = TrueThe sandbox contents are subsequently committed to the source Skill:
python for root, _, files in os.walk(sandbox): for fn in files: src = os.path.join(root, fn) rel = os.path.relpath(src, sandbox) dst = os.path.join(skill_dir, rel) os.makedirs(os.path.dirname(dst), exist_ok=True) shutil.copyfile(src, dst)Technical Analysis
The
applyoperation persistently alters other Skills by:- Appending a self-evolution instruction section to their ...[truncated 2166 chars]
- Remediation
View remediation
Remediation Suggestions
- Require explicit, per-Skill confirmation before changing any target.
- Support a mandatory allowlist rather than scanning and modifying every writable Skill by default.
- Display an exact unified diff and the list of files to be created before committing.
- Make instruction injection and learner installation opt-in, separate actions.
- Store learning data outside target Skill packages in a clearly scoped application-data directory.
- Provide a dry-run mode as the default and require an explicit commit flag for persistent changes.
- Record cryptographic hashes and backups so every modification can be audited and safely reverted.
- Minimize stored data and avoid persisting sensitive user notes or preferences without informed consent.
