T02 · Agent Memory Poisoning
Error
- Location
- scripts/migrate.sh:185
- Finding
- Unauthenticated Backup Restoration Can Poison Persistent Agent State<![CDATA[ ## Vulnerability Details **File Location**: `scripts/migrate.sh:185-234` **Vulnerability Type**: Unauthenticated restoration of instruction-bearing Agent state **Risk Level**: High ### Vulnerable Code ```bash TMPDIR=$(mktemp -d) if echo "$BACKUP_FILE" | grep -q "\.enc$"; then if [ -n "${MIGRATE_PASSWORD:-}" ]; then PASS="$MIGRATE_PASSWORD" else echo -n " 🔑 Enter decryption password: " read -s PASS echo "" fi openssl enc -aes-256-cbc -d -salt -pbkdf2 -pass "pass:$PASS" -in "$BACKUP_FILE" | tar -xzf - -C "$TMPDIR" else tar -xzf "$BACKUP_FILE" -C "$TMPDIR" fi RESTORE_DIR=$(ls -d "$TMPDIR"/openclaw-export-* 2>/dev/null | head -1) if [ -z "$RESTORE_DIR" ]; then echo "❌ Invalid backup format" rm -rf "$TMPDIR" exit 1 fi # Show manifest if [ -f "$RESTORE_DIR/manifest.json" ]; then echo " 📋 Backup from: $(cat "$RESTORE_DIR/manifest.json")" fi # Restore config if [ -d "$RESTORE_DIR/config" ]; then echo " → Restoring config" cp "$RESTORE_DIR/config/openclaw.json" "$OC_HOME/openclaw.json" 2>/dev/null && echo " ✅ openclaw.json" chmod 600 "$OC_HOME/openclaw.json" if [ -d "$RESTORE_DIR/config/agents" ]; then cp -R "$RESTORE_DIR/config/agents/"* "$OC_HOME/agents/" 2>/dev/null && echo " ✅ agents/" find "$OC_HOME/agents" -name "*.json" -exec chmod 600 {} \; fi fi # Restore workspace if [ -d "$RESTORE_DIR/workspace" ]; then echo " → Restoring workspace" for f in "$RESTORE_DIR/workspace"/*.md; do [ -f "$f" ] && cp "$f" "$OC_WORKSPACE/" && echo " ✅ $(basename $f)" done for dir in memory knowledge .learnings scripts skills; do if [ -d "$RESTORE_DIR/workspace/$dir" ]; then mkdir -p "$OC_WORKSPACE/$dir" cp -R "$RESTORE_DIR/workspace/$dir/"* "$OC_WORKSPACE/$dir/" 2>/dev/null && echo " ✅ $dir/" fi done fi ``` ### Technical Analysis The restore operation accepts a user-supplied archive and installs its contents into the active OpenClaw configuration and workspace wi ...[truncated 2080 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Digitally sign every backup with a trusted signing key and verify the signature before extraction. 2. Reject unsigned or invalidly signed archives by default. Do not rely on the directory name or manifest contents as proof of authenticity. 3. Use a strict manifest containing hashes, normalized relative paths, file types, and expected components. Verify every entry before copying it into the live workspace. 4. Present a component-level restoration summary and require separate confirmation before restoring Agent instructions, memory, scripts, or skills. 5. Restore into a staging directory first and scan instruction-bearing and executable content before activation. 6. Restrict archive entries to regular files and approved directories. Reject absolute paths, traversal components, hard links, symbolic links, device files, and unexpected file types. 7. Preserve an existing workspace backup so that poisoned state can be rolled back safely. ]]>
