T02 · Agent Memory Poisoning
- Location
scripts/compress.py:113- Finding
Untrusted LLM Output Can Poison Persistent Agent Memory
- Content
View full analysis
str: return f""" Compress this markdown into caveman format. STRICT RULES: - Do NOT modify anything inside ``` code blocks - Do NOT modify anything inside inline backticks - Preserve ALL URLs exactly - Preserve ALL headings exactly - Preserve file paths and commands - Return ONLY the compressed markdown body — do NOT wrap the entire output in a ```markdown fence or any other fence. Inner code blocks from the original stay as-is; do not add a new outer fence around the whole file. Only compress natural language. TEXT: {original} """ ``` ```python # Step 1: Compress print("Compressing with Claude...") compressed = call_claude(build_compress_prompt(original_text)) if compressed is None or not compressed.strip(): print("❌ Compression aborted: Claude returned an empty response.") print(" Original file is untouched (no backup created).") return False if compressed.strip() == original_text.strip(): print("❌ Compression aborted: output is identical to input.") print(" Likely causes: Claude refused, returned the prompt verbatim, or the file is") print(" already in caveman form. Original file is untouched (no backup created).") return False # Save original as backup, then verify the backup readback before # touching the input file. If the filesystem dropped bytes (encoding, # antivirus, disk full), unlink the bad backup and abort instead of # leaving the user with a corrupt backup + compressed primary. backup_path.write_text(original_text) backup_readback = backup_path.read_text(errors="ignore") if backup_readback != original_text: print(f"❌ Backup write verification failed: {backup_path}") print(" In-memory original d ...[truncated 3986 chars]- Remediation
View remediation
