T02 · Agent Memory Poisoning
- Location
scripts/correction_logger.py:190- Finding
Persistent Agent Memory Poisoning Through Untrusted Correction Records
- Content
View full analysis
str: # Generate the correction ID timestamp = datetime.now().isoformat() unique_str = f"{timestamp}{user_input}{agent_response}{corrected_response}" correction_id = f"corr_enh_{hashlib.md5(unique_str.encode()).hexdigest()[:12]}" # Prepare context and tags context_json = json.dumps(context, ensure_ascii=False) if context else "{}" tags_json = json.dumps(tags, ensure_ascii=False) if tags else "[]" # Prepare the backward-compatible Markdown representation display_time = datetime.now().strftime("%Y‑%m‑%d %H:%M:%S") context_str = "" if context: try: context_str = f" [上下文: {json.dumps(context, ensure_ascii=False)[:100]}...]" except (TypeError, ValueError): context_str = f" [上下文: {str(context)[:100]}...]" markdown_line = ( f"- **{display_time}** 用户纠正: {user_input} | " f"代理回应: {agent_response} | " f"纠正后: {corrected_response}{context_str}\n" ) try: with self._get_connection() as conn: cursor = conn.cursor() cursor.execute(''' INSERT INTO corrections ( id, timestamp, user_input, agent_response, corrected_ ...[truncated 5321 chars]- Remediation
View remediation
