T02 · Agent Memory Poisoning
Error
- Location
- SKILL.md:77
- Finding
- Attacker-Controlled Entries Can Be Promoted into Persistent Agent Memory<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 77-100 and 115-147 **Vulnerability Type**: Persistent memory poisoning through unsanitized input **Risk Level**: High ### Vulnerable Code ```bash log_memory() { local event_type="$1" local description="$2" local importance="${3:-normal}" local date="$(date -I)" local time="$(date '+%H:%M')" local memory_file="/home/bot/.openclaw/workspace/memory/$date.md" # ファイル存在確認・作成 if [[ ! -f "$memory_file" ]]; then create_daily_memory fi # 重要度マーカー local marker="" case "$importance" in "high") marker="🔴 " ;; "medium") marker="🟡 " ;; "low") marker="⚪ " ;; *) marker="📝 " ;; esac # ログエントリ追加 echo "" >> "$memory_file" echo "### $time - $event_type" >> "$memory_file" echo "$marker$description" >> "$memory_file" echo "メモリログ追加: $event_type [$importance]" } ``` ```bash curate_weekly_memories() { local workspace="/home/bot/.openclaw/workspace" local memory_file="$workspace/MEMORY.md" local week_start="$(date -d '7 days ago' -I)" local today="$(date -I)" echo "## 週次メモリキュレーション ($week_start to $today)" >> "$memory_file" # 過去7日間の重要な出来事を抽出 for i in {0..6}; do local check_date="$(date -d "$i days ago" -I)" local daily_file="$workspace/memory/$check_date.md" if [[ -f "$daily_file" ]]; then # 高重要度の出来事を抽出 grep -E "🔴|高重要|重要な" "$daily_file" >> /tmp/important-events.txt fi done # 重要な出来事をMEMORY.mdに統合 if [[ -s /tmp/important-events.txt ]]; then echo "### 重要な出来事" >> "$memory_file" cat /tmp/important-events.txt >> "$memory_file" echo "" >> "$memory_file" fi # 学習したパターンを記録 echo "### 学習したパターン" >> "$memory_file" grep -h "学習" "$workspace/memory"/*.md | tail -10 >> "$memory_file" # クリーンアップ rm -f /tmp/important-events.tx ...[truncated 2224 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Treat all logged and externally sourced content as untrusted data, never as agent instructions. 2. Store memories in a structured format such as JSON with separate fields for content, provenance, trust level, creation time, and reviewer identity. 3. Do not let a caller-controlled importance value automatically qualify content for long-term promotion. 4. Require explicit trusted review before copying untrusted entries into `MEMORY.md`. 5. Escape Markdown headings, code fences, HTML comments, and other document-control syntax before writing user-controlled content. 6. Add a fixed warning to recalled content stating that it is historical data and must not override system, developer, or current-session instructions. 7. Promote entries by immutable record identifier after review rather than by searching for attacker-influenceable text markers. 8. Restrict memory-file permissions and record an audit trail for creation, review, modification, and promotion operations. ]]>
