T02 · Agent Memory Poisoning
- Location
agent_memory/security.py:9- Finding
Persistent Agent-Instruction Injection Through Multiline Pinned Memory
- Content
View full analysis
", re.IGNORECASE), re.compile(r"```(?:bash|sh|shell)?", re.IGNORECASE), ] def sanitize_text(text: str) -> str: cleaned = ZERO_WIDTH_RE.sub('', text) cleaned = CONTROL_RE.sub('', cleaned) return cleaned.strip() def is_safe_memory_text(text: str) -> bool: cleaned = sanitize_text(text) if not cleaned: return False return not any(pattern.search(cleaned) for pattern in BLOCKLIST) def require_safe_memory_text(text: str) -> str: cleaned = sanitize_text(text) if not cleaned: raise ValueError('empty memory text') for pattern in BLOCKLIST: if pattern.search(cleaned): raise ValueError(f"unsafe memory text: blocked by pattern {pattern.pattern}") return cleaned ``` `agent_memory/storage.py:238-277`: ```python def append_core_memory(root: str | Path, category: str, text: str, source: str = 'agent', pinned: bool = False, supersedes: str | None = None, state: str = 'active') -> Path: paths = init_memory_root(root) target = paths.core_file(category) cleaned = require_safe_memory_text(text) if supersedes: # Validate that the supersedes ID actually exists found_target = False for core_file in paths.core_dir.glob('*.md'): ...[truncated 5808 chars]- Remediation
View remediation
