T02 · Agent Memory Poisoning
- Location
scripts/sync-learnings.py:273- Finding
Untrusted failure lessons are promoted into persistent agent instruction files
- Content
View full analysis
Vulnerability Details
File Location:
scripts/sync-learnings.py:273-286;scripts/auto-promote.py:41-68, 107-118, 158-208, 257-292;SKILL.md:446-455
Vulnerability Type: Persistent agent memory poisoning through unvalidated rule promotion
Risk Level: HighVulnerable Code
scripts/sync-learnings.py:273-286converts the lesson from a failure record directly into a proposed rule:python # 4. promotable.json — 승격 후보 목록 (auto-promote.py 입력) promotable_path = learnings_dir / "promotable.json" promotable = [] for key, pat in analysis["repeated_patterns"].items(): promotable.append({ "pattern_key": key, "type": pat["type"], "count": pat["count"], "title": pat["titles"][0], "cause": pat["cause"], "lesson": pat["lesson"], "first_seen": pat["dates"][0], "last_seen": pat["dates"][-1], "suggested_rule": pat["lesson"], })scripts/auto-promote.py:41-68interpolates the proposed rule and other record fields without validation or escaping:python def format_agents_md_row(item: dict, today: str) -> str: """AGENTS.md 자가 개선 규칙 테이블 행 포맷.""" rule = item["suggested_rule"] type_code = item["type"] count = item["count"] title = item["title"] return f"| {today} | {rule} | [{type_code}] {count}회 반복 — {title} |" def format_claude_md_rule(item: dict) -> str: """CLAUDE.md 규칙 포맷 (Claude Code 호환).""" return f"- **{item['type']}**: {item['suggested_rule']} (반복 {item['count']}회, 원인: {item['cause']})" def format_cursorrules(item: dict) -> str: """.cursorrules 포맷 (Cursor IDE 호환).""" return f"- {item['suggested_rule']}" def format_plain(item: dict, today: str) -> str: """범용 마크다운 규칙.""" return ( f"### [{item['type']}] {item['title']}\n" f"- **Rule:** {item['suggested_rule']}\n" f"- **Count:** {item['count']}회\n" ...[truncated 4196 chars]- Remediation
View remediation
Remediation Suggestions
- Change automatic promotion into proposal generation. Never modify authoritative agent instruction files without explicit human approval.
- Store candidates in a separate review file that agents do not interpret as instructions.
- Record provenance for every failure entry, including creator, source session, timestamp, and approval status.
- Validate candidate JSON against a strict schema. Enforce expected types, length limits, permitted failure types, and safe character sets.
- Apply a security policy to reject proposed rules that request secret access, network communication, command execution, permission changes, disabling safeguards, or changes to higher-priority instructions.
- Escape Markdown table delimiters, headings, HTML, links, and multiline instruction content before rendering.
- Restrict promotion targets to a canonical allowlist under the intended workspace. Resolve paths and reject absolute paths, parent traversal, symbolic-link escapes, and unexpected file types.
- Require atomic writes with backups and produce a reviewable diff before replacement.
- Separate candidate authors from approvers where the environment supports multiple identities.
- Treat
.learnings/promotable.jsonas untrusted input even when generated locally; verify its integrity and permissions before use.
