T02 · Agent Memory Poisoning
- Location
hooks/session/start/handler.js:43- Finding
Persistent Conversation Content Is Reintroduced with System-Level Authority
- Content
View full analysis
m.role === 'user' || m.role === 'assistant'); const recent = conversational.slice(-n); return recent.map(m => ({ role: m.role, content: typeof m.content === 'string' ? m.content.substring(0, MAX_CONTENT_PER_MSG) : String(m.content || '').substring(0, MAX_CONTENT_PER_MSG) })); } ``` From `hooks/session/compact:before/handler.js:89-100`: ```js // Strip old recent_messages block if present const markerIdx = existing.indexOf(RECENT_MESSAGES_MARKER); const summaryPart = markerIdx >= 0 ? existing.substring(0, markerIdx).trimEnd() : existing.trimEnd(); const timestamp = new Date().toLocaleTimeString(); const newEntry = `## ${timestamp}\n${summary}`; const separator = summaryPart ? '\n\n---\n\n' : ''; const recentBlock = `\n\n${RECENT_MESSAGES_MARKER}\n${JSON.stringify(recentMessages, null, 2)}`; const content = newEntry + separator + summaryPart + recentBlock; await writeFile(filePath, content, 'utf8'); ``` From `hooks/session/start/handler.js:43-61`: ```js for (const file of filesToLoad) { const content = await readFile(join(memoryDir, file), 'utf8').catch(() => null); if (!content) continue; // Extract the recent_messages block from the first (most recent) file only if (!recentMessagesBlock && content.includes(RECENT_MESSAGES_MARKER)) { const markerIdx = content.indexOf(RECENT_MESSAGES_MARKER); const blockStart = content.indexOf('\n', markerIdx) + 1; recentMessagesBlock = content.substring(blockStart).trim(); // Summary is everything before the marker const summaryPart = conten ...[truncated 4250 chars]- Remediation
View remediation
