T02 · Agent Memory Poisoning
- Location
session-manager.sh:18- Finding
Untrusted Content Can Poison Persistent Agent Memory
- Content
View full analysis
Vulnerability Details
File Location:
session-manager.sh:11-14, 18-21, 37-39
Vulnerability Type: Persistent storage of attacker-controlled agent context
Risk Level: MediumVulnerable Code
bash function read_last_session() { if [ -f $LAST_SESSION_FILE ]; then cat $LAST_SESSION_FILE fi } function append_session_point() { local timestamp=$(date "+%Y-%m-%d %H:%M:%S") local point="$1" echo -e "\n## [$timestamp] $point" >> $LAST_SESSION_FILE }bash append) append_session_point "$2" ;;Technical Analysis
The
appendoperation accepts arbitrary caller-controlled text and writes it directly intolast-session-summary.mdwithout validation, trust labeling, escaping, or provenance metadata. Thereadoperation subsequently emits the stored content verbatim.The skill documentation states that this output is intended to restore context when a new agent session starts. If the restored summary is inserted into an agent's context, malicious text can pose as trusted instructions rather than historical user-supplied data. For example, an attacker could store directives asking the agent to ignore current policies, reveal information, or execute unsafe actions in future sessions.
Although the script itself does not invoke an AI model or install an automatic startup hook, it establishes the complete persistent storage and retrieval channel needed for cross-session prompt injection when integrated as documented.
Attack Path
- An attacker supplies instruction-like content through the second argument of the
appendcommand. append_session_pointwrites the content unchanged to./memory/sessions/last-session-summary.md.- The content remains present after the current interaction ends.
- A later session invokes the
readoperation as part of the documented context-restoration workflow. - The stored attacker-controlled text is emitted verbatim ...[truncated 743 chars]
- An attacker supplies instruction-like content through the second argument of the
- Remediation
View remediation
Remediation Suggestions
- Store session records in a structured format with explicit fields for content, author, timestamp, source, and trust level.
- Treat restored summaries strictly as untrusted historical data, never as system-level or developer-level instructions.
- Place restored content inside a clearly delimited data section and explicitly instruct the consuming agent not to execute directives contained within it.
- Validate or reject entries containing instruction-like control text when such content is not necessary for the feature.
- Preserve provenance through summarization and archival operations.
- Require user confirmation before restoring entries from untrusted sources.
- Restrict which application components and users are allowed to invoke the
appendoperation. - Consider integrity protection, such as an authenticated record format, if multiple processes can modify the memory files.
