T02 · Agent Memory Poisoning
- Location
src/execute_task.py:1118- Finding
Persistent Memory Poisoning Through Unsanitized Task Content
- Content
View full analysis
Vulnerability Details
File Location:
src/execute_task.py:1118-1153
Vulnerability Type: Persistent injection of attacker-controlled content into Agent memory
Risk Level: HighVulnerable Code
python def _generate_memory_entry(self, task: str, result: Dict) -> str: """Generate a memory entry.""" timestamp = datetime.now().strftime("%Y-%m-%d %H:%M") task_name = result.get("task", task) entry = f"""--- ## {task} **Time**: {timestamp} **Description**: {task_name} **Execution status**: {result.get("status", "unknown")} **Key information**: - Method: {result.get("method", "unknown")} - Duration: {result.get("duration", "N/A")} - Resources: {result.get("resources", [])} **Memory content**: {result.get("memory_content", "")} --- """ return entry def _save_memory_entry(self, task: str, result: Dict) -> str: """Save the memory entry to a file.""" path = os.path.join(MEMORY_PATH) timestamp = datetime.now().strftime("%Y-%m-%d") filename = f"{timestamp}.md" filepath = os.path.join(Memory_Daily_DIR, filename) with open(filepath, 'a', encoding='utf-8') as f: f.write(f"\n## Memory maintenance record\n\n{result.get('memory_entry', '')}") return filepathTechnical Analysis
The task text, result task value, and
memory_contentvalue are directly interpolated into a Markdown memory entry. The resulting entry is appended to persistent daily memory without validation, escaping, provenance metadata, or separation between trusted instructions and untrusted task data.Markdown memory files are likely to be supplied to an Agent as contextual state in later sessions. Consequently, an attacker can submit content that resembles operational instructions, security exceptions, tool-use directives, or fabricated user preferences. When later loaded as memory, that content may be interpreted as trusted conte ...[truncated 1368 chars]
- Remediation
View remediation
Remediation Suggestions
- Store task data in a structured format such as JSON rather than executable or instruction-like Markdown.
- Attach explicit provenance fields, including source, timestamp, trust level, and whether the content was user-supplied.
- Escape Markdown headings, delimiters, links, and other control syntax before persistence.
- Reject or quarantine content that resembles system instructions, tool directives, authorization changes, or requests to override prior rules.
- Ensure memory consumers treat persisted task text strictly as quoted data, never as instructions.
- Require explicit user confirmation before promoting any generated entry to permanent memory.
- Apply length limits and an allowlist schema to
task,memory_content, and other persisted fields. - Keep untrusted task history physically separate from trusted preferences and permanent configuration.
