T02 · Agent Memory Poisoning
- Location
log_correction.py:20- Finding
Untrusted Corrections Can Poison Persistent Agent Memory
- Content
View full analysis
Vulnerability Details
File Location:
log_correction.py:20-44; related retrieval occurs atcheck_memory.py:35-44andcheck_memory.py:71-74
Vulnerability Type: Persistent storage of untrusted behavioral instructions
Risk Level: HighVulnerable Code
python entry = { "type": "correction", "timestamp": datetime.now().isoformat(), "topic": topic, "wrong": wrong, "correct": correct, "context": context, "count": 1 } corrections_file = f"{MEMORY_DIR}/corrections.jsonl" if os.path.exists(corrections_file): with open(corrections_file, "r") as f: for line in f: try: old = json.loads(line.strip()) if old.get("topic") == topic and old.get("wrong") == wrong: entry["count"] = old.get("count", 1) + 1 break except: pass with open(corrections_file, "a") as f: f.write(json.dumps(entry, ensure_ascii=False) + "\n")The stored correction is subsequently selected and displayed by
check_memory.py:python corrections_file = f"{MEMORY_DIR}/corrections.jsonl" if os.path.exists(corrections_file): with open(corrections_file, "r") as f: for line in f: try: entry = json.loads(line.strip()) if entry.get("topic", "").lower() in command.lower(): results.append(("correction", entry)) except: passTechnical Analysis
The correction logger accepts arbitrary values for
topic,wrong,correct, andcontextand stores them in long-term JSONL memory without validating their source, intent, scope, or content. There is no separation between descriptive data and instructions that may influence future Agent behavior.The documented skill workflow instructs the Agent to record user corrections automatically a ...[truncated 1971 chars]
- Remediation
View remediation
Remediation Suggestions
- Require explicit user confirmation before persisting any behavioral correction.
- Store provenance metadata, including the originating user, session, project, timestamp, and approval status.
- Scope corrections to a specific project by default rather than using global memory.
- Reject content that attempts to override security policies, approval requirements, tool restrictions, credential handling, or system instructions.
- Treat retrieved memory as untrusted quoted data, not executable or authoritative Agent instructions.
- Do not automatically copy user-controlled corrections into
AGENTS.md,MEMORY.md, or other instruction-bearing files. - Add review, revocation, expiry, and audit-log mechanisms for all persistent corrections.
- Apply integrity protection or authenticated storage where other local processes or users could modify the memory files.
