T02 · Agent Memory Poisoning
- Location
run.py:106- Finding
Persistent Memory Can Store and Replay Attacker-Controlled Instructions
- Content
View full analysis
string conversion? prefer explicit string for VECTOR literal cursor.execute("INSERT INTO knowledge_vault (content, embedding) VALUES (%s, %s)", (content, vec_str)) return {"success": True, "message": "Content embedded and stored."} elif action == "search": if not query: return {"success": False, "error": "Query required"} q_vec = get_embedding(query) q_vec_str = str(q_vec) # Vector Search SQL (Security Fix: Parameterize LIMIT) sql = """ SELECT content, VEC_COSINE_DISTANCE(embedding, %s) as distance FROM knowledge_vault ORDER BY distance ASC LIMIT %s """ cursor.execute(sql, (q_vec_str, int(limit))) results = [] for row in cursor.fetchall(): results.append({"content": row[0], "distance": float(row[1])}) ``` ### Technical Analysis The protocol directs the agent to persist user-provided context, while the implementation stores the supplied `content` verbatim. Search results are subsequently returned as raw text without provenance, trust metadata, instruction filtering, or a boundary identifying the result as untrusted data. SQL parameterization prevents SQL injection, bu ...[truncated 1335 chars]- Remediation
View remediation
