T02 · Agent Memory Poisoning
- Location
index.js:203- Finding
Persistent prompt injection through automatically stored and recalled messages
- Content
View full analysis
{}); if (context.length > 0) { // Filter out previously injected context blocks const filtered = context.filter(m => !m.observation.includes('')); if (filtered.length > 0) { const contextBlock = filtered.map(m => `- ${m.observation}`).join('\n'); return `[Recalled Memory]\n${contextBlock}\n\nUser: ${userMessage}`; } } return userMessage; } ``` The related response-saving behavior at `index.js:227-237` also accepts agent-generated text without validating whether it contains instructions: ```javascript async onResponse(agentResponse, sessionId) { if (!this.apiKey) return; if (!agentResponse || agentResponse.length < 20) return; // Skip responses that contain injected memory context if (agentResponse.includes('')) return; const observation = agentResponse.length > 500 ? agentResponse.slice(0, 500) + '...' : agentResponse; this.remember(observation, ['role:assistant', `session:${sessionId}`]).catch(() => {}); } ``` ### Technical Analysis Every non-command user message of at least 15 characters is automatically persisted. Recalled observations are subsequently concatenated directly into the text sent to the downstream language model. The recalled content is not escaped, assigned a trustworthy provenance level, structurally separated from instructio ...[truncated 2781 chars]- Remediation
View remediation
