T01 · Skill Instruction Hijacking
- Location
persistentmind.py:237- Finding
Persistent prompt injection through untrusted imported memories
- Content
View full analysis
str: """ Get a formatted context block of the most relevant memories. Designed to be injected into AI prompts. """ proj = project or self.project memories = [m for m in self.memories if not m.archived and ( m.scope == MemoryScope.GLOBAL or (m.scope == MemoryScope.PROJECT and m.project == proj) or (m.scope == MemoryScope.SESSION and m.session_id == self.session_id) )] # Sort: corrections first (most important), then by importance desc memories.sort(key=lambda m: ( 0 if m.memory_type == MemoryType.CORRECTION else 1, -m.importance )) lines = ["# Relevant Memory Context\n"] char_budget = max_tokens_estimate * 4 used = 0 for m in memories: type_icon = { "fact": "📌", "preference": "⚙️", "procedure": "📋", "context": "🗂️", "correction": "⚠️", "relationship": "🔗", "reminder": "🔔" }.get(m.memory_type, "•") line = f"{type_icon} [{m.memory_type.upper()}] {m.content}" if m.tags: line += f" (tags: {', '.join(m.tags)})" line += "\n" used += len(line) if used > char_budget: lines.append(f"... ({len(memories) - len(lines) + 1} more memories truncated)") break lines.append(line) return "\n".join(lines) ``` ```python def import_memories(self, input_file: str, overwrite_duplicates: bool = False): """Import memories from a JSON export file.""" with open(input_file) as f: data = json.load(f) existing_ids = {m.id for m in self.memories} imported = 0 skipped = 0 for item in data.get("memo ...[truncated 2513 chars]- Remediation
View remediation
