arXiv(opens in a new tab)cs.CRAug 2026Cited by 2 papers on PaperVantage

Manuscript Offprint

arXiv:2608.23471

InjecMEM: Memory Injection Attack on LLM Agent Memory Systems

Hanling Tian, Gengyu Zhang, Zeyang Sha, Jingying Wang, Yuhang Liu, Zhehao Huang, Kun Yang, Xiaolin Huang

Abstract

Memory is becoming a default subsystem in deployed LLM agents to provide persistent personalization and continuity. This naturally prompts a question: will memory system introduce new vulnerabilities into agents? Thus we propose InjecMEM, a novel memory injection attack paradigm that requires only a single interaction (no read/edit access to memory store) to steer later responses of related queries toward a pre-specified output. Guided by the retrieval-then-generate mechanism of memory systems, we craft the injection with a retriever-agnostic anchor and an adversarial command. The anchor contains high-recall topical cues so that downstream retrieval consistently associates the record with the target topic. The command is a short sequence optimized to remain effective under uncertain fused contexts, variable placements, and long prompts so that it reliably steers outputs once retrieved. We learn the command via gradient-based coordinate search, averaging over synthetic prompt templates and insertion positions, and extend it to joint optimization across backbones to study transfer. Evaluated across multiple memory systems and backbone models, InjecMEM achieves reliable topic-conditioned retrieval and targeted generation, remains effective under memory drift, and leaves non-target queries unaffected. Our results underscore the need to harden memory systems and provide a reproducible framework for studying agent memory. Code is available at https://github.com/BlueBlood6/InjecMEM.

1 Introduction

Large language models (LLMs) have demonstrated remarkable capabilities, leading to the widespread adoption of LLM-based agents in healthcare (Abbasian et al., 2023; Shi et al., 2024; Li et al., 2024a), finance (Yu et al., 2025), and personal digital assistants (Moniz et al., 2024; Li et al., 2024b). An agent is a system comprising a perception module for user inputs, an LLM core for reasoning and response generation, and tools for specialized tasks. Beyond these internal components, agents often integrate external auxiliary subsystems. A retrieval-augmented generation (RAG) (Lewis et al., 2020) module connects to external knowledge sources to improve factual accuracy, while a memory module persistently logs and later retrieves interactions to support long-term coherence across multi-turn conversations.

Memory is rapidly becoming the default way to deliver long-horizon personalization and continuity in real deployments. Its promise is substantial, enabling adaptation across sessions, stable user preferences, and improved dialogue coherence without repeatedly collecting context from scratch. Yet, as with every capability module added to agents, the memory system also enlarges the attack surface. Beyond improving performance, we therefore ask: What new vulnerabilities emerge once agents continuously write to and read from a persistent memory system store? Studying attacks on memory systems is meaningful given their growing deployment. It is challenging because the write-retrieve loop is non-stationary, retrieval yields variable context across queries, and retrieval is multi-signal rather than

∗^{*}Equal contribution. †^{\dagger}Corresponding author.

Stage1: Poisoning Interaction

Figure

Stage2: Attack Benign Queries

Figure 1: InjecMEM attack pipeline. The attacker inputs adversarial prompt, memory logs it. Benign users query about τ\tau, the poisoned page will be retrieved and thus steers responses.

purely embedding-based. A principled analysis of these issues is necessary to understand and secure memory-augmented agents.

At first glance, memory systems resemble RAG because both retrieve records to support response generation; however, the similarity is superficial in practice. Memory systems continuously record and update, while RAG indices are typically static. RAG poison method (Chen et al., 2024) that assumes a fixed embedding geometry becomes brittle under distribution shift. For attackers, the fused prompt is often long and diverse, blending long-term memories, short-term snippets and user attributes. The poisoned record shifts position within this evolving prompt and its context changes across runs. The memory drift dynamics can weaken the influence of the poisoned memory on the final response. Moreover, modern memory systems often use hybrid retrieval for better memory management instead of pure vector search. These factors violate core assumptions behind static, trigger-optimization attacks in RAG and explain why prior methods do not transfer directly.

In this paper, we introduce InjecMEM (Injection attack on MEMORY systems), a targeted red-teaming attack paradigm on agent memory systems with just one interaction and no read/edit access to the memory store. The attacker specifies a target topic and target output, aiming to make the agent generate that output for later queries on the topic (Fig. 1). InjecMEM splits the crafted injection into two cooperating parts. The first part is a retriever-agnostic anchor that contains high-recall topical cues, biasing downstream indexing and retrieval to associate the poisoned record with the target topic. The second part is an adversarial command, a short sequence optimized to steer the LLM to a specified target output whenever the poisoned record appears in the final LLM input. We learn the command via gradient-based coordinate search, averaging likelihood over diverse prompt templates and insertion positions to improve robustness of uncertain fused contexts, variable placements, and long prompts under memory drift. We further extend it to joint optimization across backbones for transfer. By pairing topic-consistent storage with robustness to memory drift, InjecMEM succeeds without modifying the memory store.

We evaluate InjecMEM primarily on a recent memory system (MemoryOS) and additionally a widely used agent framework (MemGPT), across multiple domains (e.g., health, finance) and backbone models. On MemoryOS, InjecMEM substantially outperforms baseline attacks, achieving up to 35.4% retrieval success rate (RSR) and 76.6% attack success rate (ASR). The attack persists under benign memory drift, while non-target queries remain largely unaffected. Beyond single-model optimization, we show transfer within a model family, including from smaller models to larger ones and to fine-tuned variants, and we further perform joint optimization across model families, where success is largely confined to the optimized backbones. We further demonstrate that a simple concatenation of commands optimized for different backbones can compromise all of them, highlighting practical risk when attackers target widely used open-source backbones and the fine-tuned derivatives.

Our technical contributions are summarized as follows:

• We identify and formalize a core vulnerability of agent memory: continuous writes and hybrid retrieval jointly create a distinct, underexplored attack surface.

• We propose InjecMEM, an injection attack that interacts with agents using crafted prompt and causes subsequent queries on target topic to yield the pre-specified output.

• We validate InjecMEM across multiple memory systems and backbones, including within-family transfer, concatenation-based coverage of candidate backbones.

References (63)