T02 · Agent Memory Poisoning
- Location
handler.js:84- Finding
Untrusted Session Content Can Poison Persistent Agent Memory
- Content
View full analysis
c.type === "text")?.text || ""; } else { text = obj.message.content || ""; } const cleanText = normalizeText(text); if (isUsefulText(cleanText)) { result.push({ role: obj.message.role, text: cleanText }); } } ``` ```js const historyText = messages.map((m) => `[${m.role.toUpperCase()}]: ${m.text}`).join("\n"); const providerConfig = await getProviderConfig(); if (!providerConfig || !providerConfig.apiKey || !providerConfig.baseUrl) { throw new Error("Local config lacks the specified provider or keys."); } const reqBody = { model: "ark-code-latest", messages: [ { role: "system", content: SYSTEM_PROMPT }, { role: "user", content: "以下是原始会话:\n\n" + historyText }, ], temperature: 0.3, }; const res = await fetch(`${providerConfig.baseUrl}/chat/completions`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${providerConfig.apiKey}`, }, body: JSON.stringify(reqBody), }); if (!res.ok) throw new Error(`API HTTP ${res.status}`); const json = await res.json(); const aiSummary = json.choices?.[0]?.message?.content; if (!aiSummary) throw new Error("Empty AI response"); const timeStr = `${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`; await fsPromises.mkdir(memoryDir, { recursive: true }); let block = ""; if (!existsSync(archiveFile)) { block += `# ${dateStr} 工作记忆\n\n`; } block += `---\n\n## 🧾 会话整理 - ${dateStr} ${timeStr}\n- Session ID: ${sessionId}\n\n${aiSummary}\n\n`; await fsPromises.appendFile(archiveFile, block, "utf8"); ``` ### Te ...[truncated 2613 chars]- Remediation
View remediation
