From similarity to vulnerability: key-collision attacks against LLM semantic cachesFrom Similarity to Vulnerability: Key Collision Attack on LLM Semantic Caching
The authors use CacheAttack-1 to hijack semantic caches, achieving HR of 86.9% on semantic cache (Table 1).
The embedding model is black-box to the attacker (parameters, vectors, and thresholds are not visible). The attacker can send arbitrary prompts, use a local proxy embedding model to optimize adversarial prompts, and infer hits via signals such as latency, hijacking responses through false-positive key collisions. The attacker does not modify cache values, access KV, control eviction, or change parameters; the attack occurs at inference time. The victim system is a semantic cache in a multi-tenant LLM agent.
- Semantic caches use embedding vectors as fuzzy keys to improve cross-tenant hit rates and reduce repeated inference. The authors state that this locality conflicts with the avalanche effect required for hash collision resistance, and attackers can hijack responses without modifying cache values, only through false positive key collisions, and further influence agent tool calls.
- CacheAttack is a generator–verifier framework: it uses GCG-style search to optimize discrete suffixes so that the source prompt and the victim prompt collide on the similarity threshold or LSH partition, and uses a Gaussian MAP of latency to determine hits. CacheAttack-2 first filters on a proxy, and the target model only performs the final verification.
- Qwen3-8B, e5 cache, bge agent, NQ 50 entries: CacheAttack-1 on semantic cache has HR 86.9%, ISR 81.1% (Table 1). Tool hijacking HR 90.6% (Table 3). The authors state that the diagonal HR exceeds 0.92.
- The paper has no dedicated limitations section. The Conclusion hopes to develop collision-resistant cache architectures that withstand adversarial manipulation. The experiments specify two caches, four embedding models, five backend LLMs, as well as salting, PPL screening, and per-user isolation; it does not report the ISR review method, λ, α, or the number of repetitions.
- Evaluated models
- sentence-transformers/all-MiniLM-L6-v2thenlper/gte-smallintfloat/e5-small-v2BAAI/bge-small-en-v1.5
- Benchmarks
- Natural QuestionsSC-IPIBFCL v4 simple splitsGPTCacheSemShareKVAWS BedrockAzure API Management
- Metrics
- Hit Rate (HR)Injection Success Rate (ISR)Tool Selection Rate (TSR)Answer Accuracy (Acc)ΔTSRΔAcc
The researchers propose CacheAttack, a key-collision attack framework against LLM semantic caches, which hijacks model responses by optimizing an adversarial suffix so that malicious queries hit the same cache key as benign queries. The paper models semantic cache keys as locality-preserving fuzzy hashes and points out an inherent conflict with the avalanche effect required for collision resistance. On GPTCache and SemShareKV with Qwen3-8B as the backend, CacheAttack-1 achieves an average hit rate above 0.86 and an injection success rate above 0.82; in the agent tool-calling scenario, the hit rate reaches 90.6%, tool selection drops by up to 84.5%, and answer accuracy drops by 83.8%, and it can transfer across embedding models. In the financial agent case, the attack triggers an unauthorized sell order. For defenses, key salting, perplexity screening, and per-user cache isolation are evaluated, all with efficiency-security trade-offs.
Why it was selectedThe paper models semantic cache keys as fuzzy hashes, provides attack success rates for cross-model transfer and the trade-offs of three defenses, and teams deploying multi-tenant caches can use this to assess integrity risks.
Paper analysis
What problem does this paper attempt to solve?
The locality of semantic caches conflicts with collision resistance; black-box key collisions can hijack responses.
Semantic caches use embeddings as fuzzy matching keys, which conflicts with the avalanche effect needed for locality preservation and collision resistance, so they can be hijacked by key collisions.
- Scenario: The authors state that AWS and Microsoft deploy semantic caches at the application layer, using embedding vectors for fuzzy matching to reduce latency and computation for repeated inference. In multi-tenant settings, a single false positive hit can deliver a cached result controlled by someone else to the current user.
- Existing research: The authors state that prior work mainly studied privacy leakage and prompt recovery under timing side channels; integrity breaches in semantic caches remain largely unexplored.
- Observation: The authors view semantic keys as locality-preserving fuzzy hashes: the key distance for similar queries tends to 0, while the avalanche effect requires that distance to approach the maximum. Coarse thresholds or coarse partitioning improve hit rates but introduce false positive collisions; Lemma 3.1 provides a lower bound on the false positive probability under hit conditions.
- This paper's approach: The authors propose a black-box framework, CacheAttack, which searches for adversarial suffixes to trigger false positive key collisions, and claim this is the first key collision attack framework against semantic caches and the first systematic study of integrity risks.
- Threat model:
- Goal: Make benign prompts and adversarial prompts with semantically different, attacker-controlled instructions satisfy matching, causing response hijacking and further inducing harmful agent behavior.
- Knowledge: The embedding model is black-box; parameters, vectors, and similarity thresholds are invisible. Public embedding models can be used as proxies, and hit or miss can be inferred from response consistency, repeated generation patterns, and end-to-end latency.
- Capabilities: Can send arbitrary prompts and receive responses; collision targets can be chosen arbitrarily. Does not modify existing cache values, does not access internal KV, does not control eviction policies, and does not modify embedding model or backend LLM parameters. The attack occurs at inference time.
- Victim system: Semantic cache middleware in multi-tenant LLM agent frameworks. On a hit, LLM inference is skipped and stored execution plans and tool calls are returned directly. The attack targets the embedding model that computes cache keys.
What related research exists?
The authors position this paper after cache mechanisms, hash collisions, and privacy side channels, and claim a shift to integrity.
The paper positions itself in Section 2 in terms of caching mechanisms, hash properties, and existing security research.
Caching in LLMs
- KV cache (Zhao et al., 2023): stores the attention KV of processed tokens during the decoding phase, avoiding recomputation at the next step.
- Prompt caching (Gim et al., 2023; Zheng et al., 2024a): uses user prompt prefixes as keys and the corresponding KV states as values, reducing computation for repeated queries.
- Semantic caching and semantic KV caching: Bang (2023) et al. use query embeddings as keys and LLM responses as values for approximate reuse; SemShareKV (Zhao & Mastorakis, 2025) and SentenceKV (Zhu et al., 2025) index KV with semantic embeddings. The authors state that AWS (2025) and Microsoft (2025a;b) have deployed semantic caching in cross-tenant scenarios.
Hash collisions and the avalanche effect
- Consequences of collisions: Preneel (1993) discusses different inputs mapping to the same key; Maurer & Lewis (1975) point out that collisions in simple hash tables degrade lookups. The authors also cite password cracking (Oechslin, 2003) and certificate impersonation (Stevens et al., 2007) to illustrate that collisions can cause security failures.
- Avalanche effect: the strict avalanche criterion of Webster & Tavares (1985) requires that when 1 input bit is flipped, each output bit flips with 50% probability. Upadhyay et al. (2022) discuss that insufficient avalanche makes collisions more likely.
- Fuzzy hashing: Lee & Atkison (2017) compare fuzzy hashing. The authors use this concept to describe semantic keys: similar queries are mapped to the same bucket.
Cache security and poisoning
- Privacy side channels: Song et al. (2025), Zheng et al. (2024b), Gu et al. (2025), Wu et al. (2025), and Luo et al. (2025) study prompt leakage or reconstruction via timing side channels. The authors state that this paper focuses on response hijacking caused by key collisions, not this kind of privacy recovery.
- External knowledge poisoning: PoisonedRAG (Zou et al., 2025) tampers with retrieved documents or knowledge. The authors state that this paper differs: it does not directly modify cache values, but uses key collisions to decide which entry is reused.
- Concurrent observations: Wu et al. (2026a;b) observe semantic cache poisoning, or cache-related risks in LLM serving frameworks. The authors state that they are the first to formalize this phenomenon as key collisions and to write down the theoretical trade-off between locality and collision resistance.
Baselines and benchmarks
- Baseline methods: Clean (Benign) and the genetic algorithm GA (Lambora et al., 2019). GA's fitness is the cosine similarity between the adversarial query embedding and the target embedding, with the same verifier as CacheAttack.
- Benchmarks and environments: Natural Questions (Kwiatkowski et al., 2019), the authors' SC-IPI, and tool-calling data derived from the three simple splits of BFCL (Patil et al.). The semantic cache is implemented as GPTCache (Bang, 2023), and the semantic KV cache is the authors' reimplementation of SemShareKV. The industrial interfaces are AWS Bedrock and Azure API Management.
The authors position this paper after the above work: treating semantic keys as locality-preserving fuzzy hashes, and claiming this is the first systematic study of integrity risks and the first black-box key collision attack framework.
How does the paper address this problem?
CacheAttack uses a generator to search for suffixes and a latency-based verifier to determine hits, with variants of direct verification and proxy filtering.
CacheAttack is a generator–verifier framework: it searches for discrete suffixes under black-box conditions so that the source prompt and any victim prompt satisfy the semantic cache's matching condition.
Problem setting
- Keys and matching: Prompt p is embedded via f to obtain a semantic key. A semantic cache hits when similarity is not below threshold τ; semantic KV caches often use partitions such as LSH, and a hit occurs when two keys fall into the same region. The authors refer to both as fuzzy hashing.
- Trade-off: The key distance for similar queries tends to 0, while the avalanche effect requires that the hash distance for similar inputs tends to the maximum. The authors argue that coarse thresholds or coarse partitions are contrary to the separation required for collision resistance.
- Lower bound: Let B be the set of "returning cached response pc is semantically incorrect for query p", and h be the hit probability. The authors give Pr[p ∈ B ∣ match(p, pc)=true] ≥ 1 − Pr[p ∉ B]/h. The meaning is: the false positive probability under the hit condition is not less than 1 minus the probability that reuse is semantically allowed divided by h. The proof is in Appendix A.
- Attack form: The adversarial query is written as pa = psrc ⊕ s, where s is a discrete suffix of length L. It requires that the match is true, and that pa contains the attacker's instruction and is semantically different from the victim prompt. The authors state that the hijacking comes from false-positive cache hits, not from common prompt injection or backend hallucination.
Generator
- Objective: Minimize the collision loss plus λ times the whole-sentence perplexity over the suffix, with λ > 0. The perplexity is computed by a language model M, which does not participate in the cache. The paper does not give the name of M or λ. The authors state that adding perplexity is for stealth, to bypass agent input filtering.
- Semantic cache loss: 1 minus the similarity between the adversarial and victim sentence embeddings.
- Semantic KV loss: The discrete key is sign(R_LSH e(p)). Since the sign function has zero gradient, tanh(α R_LSH e(p)) is used as a continuous relaxation, with α > 0, and then the squared Euclidean distance between the two relaxed keys is minimized. The authors state that as α tends to infinity, this relaxation approaches the sign function for nonzero inputs. The paper does not give α.
- Suffix constraint: Appendix B specifies that when optimizing suffixes for indirect prompt injection, the suffix must start with a fixed phrase to avoid weakening the injection. That phrase is not repeated here.
Verifier
- Side channel: The target cache state is not visible. The authors formulate hit verification as latent variable inference, where the observation is the logarithm of execution latency.
- Statistical model: The hit indicator takes 0 or 1, and the log-latency is Gaussian within each class. The calibration set uses repeated identical requests as hits and queries with nonces as misses. The paper does not report the number of calibration entries.
- Decision: Under 0–1 loss, the class with the maximum posterior is chosen, and a hit is declared if the log-likelihood ratio is not less than 0. The authors state that dynamic recalibration is performed during probing to mitigate network jitter, rather than using a fixed threshold.
Two variants
- One iteration: First write the generated adversarial prompt into the cache, then query the original victim prompt, recording hit or miss.
- CacheAttack-1: After generation, verify directly on the target model. The authors state that frequent queries are easily detected by traffic analysis; the cache cannot be explicitly cleared, and iterations must wait for TTL, making large-scale attacks impractical. The paper does not give TTL.
- CacheAttack-2: Candidates are mainly evaluated on a proxy model; only after the expected cache behavior appears on the proxy is a single final verification performed on the black-box target. On failure, it continues to the next candidate. The authors state that interaction with the target can be reduced to one query per round.
- Budget: The generator is a search algorithm with a maximum search step limit of 1000.
How success is counted
- Response hijacking: HR is the proportion of benign queries that reuse an injected entry; ISR is the proportion of returned responses that exhibit the injected behavior. The paper does not specify whether ISR is determined by rules, humans, or a model.
- Tool hijacking: The cache entry is a tool call and its execution result. HR is defined as the probability that the retrieved result equals the target entry; tool selection rate and answer accuracy are reported as decreases relative to benign runs.
What experiments did the paper conduct?
CacheAttack-1 on semantic cache has HR 86.9%, and agent tool hijacking HR 90.6%.
Experimental setup
- Cache and backend: Semantic cache uses GPTCache with cosine threshold τ=0.8; semantic KV cache is the authors' reimplementation of SemShareKV (LSH). Main experiments use Qwen3-8B as backend. For RQ1, cache embeddings are intfloat/e5-small-v2, and suffixes are optimized on another surrogate, BAAI/bge-small-en-v1.5.
- Data: 50 benign prompts randomly sampled from Natural Questions. Malicious side is SC-IPI, 4185 indirect prompt injections generated by GPT-5.2, covering account identifiers, credentials, financial operations, and health-related scenarios, using synthetic placeholders. Appendix E explains construction; examples are not repeated here.
- Agent data: BFCL v4's simple python, java, and javascript splits are converted into source–target pairs, with tools deduplicated by name and parameter patterns. Appendix F gives the pairing format and one malicious target prompt, not repeated here. The authors state this target prompt consistently bypasses safety protections on Qwen3-8B. The paper does not report the number of pairs.
- Baselines and metrics: Clean (Benign) and GA. Metrics are HR, ISR; for agents, also TSR, Acc, ΔTSR, ΔAcc. The main text defines ISR as Injection Success Rate. The paper does not specify its reviewers or report repetitions. Search step limit is 1000.
- Other models: Transfer uses all-MiniLM-L6-v2, gte-small, e5-small-v2, bge-small-en-v1.5. Backend sensitivity additionally uses Qwen3-32B, DeepSeek-R1-0528, Llama-3.1-8B-Instruct, Mistral2-7B-Instruct-v0.2, with temperature fixed at 0.
- Industrial interfaces: AWS Bedrock and Azure API Management. The paper does not specify their embedding models, thresholds, or sample sizes. The authors state that subsequent RQs use CacheAttack-2.
Main results
The table below is based on Table 1. Conditions: Qwen3-8B, τ=0.8, 50 samples from NQ, cache embeddings e5-small-v2, surrogate bge-small-en-v1.5. Main results are reported by method, not split by backend model.
Swipe horizontally to read the table
Method Cache type HR ISR CacheAttack-1 semantic cache 86.9% 81.1% CacheAttack-1 semantic KV cache 85.8% 83.0% CacheAttack-2 semantic cache 83.1% 77.1% CacheAttack-2 semantic KV cache 80.4% 77.0% GA semantic cache 36.2% 33.7% GA semantic KV cache 34.0% 31.5% Clean both caches 0.0% 0.0% - The authors state that both CacheAttack variants can hijack LLM responses; ISR is lower than HR in the same cell because a few indirect prompt injections may be filtered by the LLM's internal defenses.
- The authors state that CacheAttack-1 is time-consuming and easily detected, so subsequent RQs use CacheAttack-2. In the table, GA is lower than both CacheAttack variants.
- Industrial interfaces report only HR (Table 2): on AWS Bedrock, Clean 0.0%, GA 12.4%, CacheAttack-1 80.6%, CacheAttack-2 78.2%; on Azure, respectively 0.0%, 15.2%, 88.3%, 86.7%. The abstract writes hit rate 86%, which differs from Table 1's notation.
Agent tool call hijacking
- What was tested: A tool pipeline with semantic cache. On a hit, LLM reasoning and real tool execution are skipped, and the cached tool call and result are returned directly. Benign runs are compared with collision attacks.
- Results: In Table 3, semantic cache HR is 90.6%, TSR drops from 93.2% benign to 8.7% under attack (ΔTSR 84.5), Acc drops from 87.0% to 3.2% (ΔAcc 83.8). Semantic KV cache HR is 87.1%, TSR drops from 93.2% to 13.1% (Δ 80.1), Acc drops from 87.0% to 7.9% (Δ 79.1). The paper does not specify the sample size or embedding model for this table.
- Authors' interpretation: The authors state TSR drops by up to 84.5% and Acc by up to 83.8%, and state this hijacks tool calls and passes errors downstream. The 90.6% in the abstract corresponds to the semantic cache HR in this table.
Cross-embedding model transfer
- What was tested: Suffixes are optimized on a surrogate embedding, and the cache is evaluated on another embedding, following the same procedure as RQ1. The four models are MiniLM, GTE, E5, BGE. The authors state that the diagonal (surrogate and target identical) corresponds to the white-box setting.
- Results: In Table 4, diagonal HR values are MiniLM 93.4%, GTE 92.1%, E5 94.0%, BGE 93.1%. The authors state all diagonal values exceed 0.92. Off-diagonal values range from 49.8% (MiniLM optimized, BGE evaluated) to 86.9% (BGE optimized, E5 evaluated). These are taken from the full Table 4, not from an interval given by the authors.
- Authors' interpretation: The authors state transfer depends on model similarity; surrogates transfer more easily to target models with closer architecture and training objectives. Appendix C states the attack also holds across backend LLMs and different thresholds.
Defenses and financial case
- Salting: A user-independent secret salt is sampled once per cache instance, implemented as a random 5-token string; both insertion and lookup compute keys on the salted input. Table 5 shows reductions relative to the unsalted baseline (percentage points). On semantic cache, Prefix ΔHR 19.2, ΔISR 25.4; Suffix 9.5, 10.2; Template 21.0, 24.8; Best behavior 21.0, 25.4. On semantic KV cache, correspondingly 10.8/20.2, 8.3/9.1, 10.7/19.8, Best 10.8/20.2. The authors state salting only slightly reduces HR and ISR, and is a lightweight mitigation, not a full defense.
- Two other defenses: At insertion, a reference language model (the paper gives GPT-2 as an example) computes perplexity; if it exceeds a calibrated threshold, the entry is not written to the shared cache. Figure 4 compares Standard PPL and Window PPL (size=5) on NQ; after text extraction, bars and conditions cannot be aligned, so bar numbers are not cited. After isolating namespaces per user, the authors state cross-user collision reuse is eliminated, but hit rate drops and backend calls, cost, tail latency, and storage increase; the performance–security trade-off is unavoidable. The latter two defenses do not have HR/ISR under the same conditions as Table 1.
- Case: The financial agent in Figure 2 uses GPTCache and Qwen3-32B and can call an order-placing tool. Benign runs give conservative advice and do not place orders. The attack first produces and writes a cached response with a sell order through the same pipeline; the authors state the attacker does not directly modify cache values. A victim's separate benign query collides and reuses that entry, executing the sell. The authors state this can cause financial harm to the victim. This case has no numerical metrics.
Other ablations and analyses
- Backend LLM (Table 6, CacheAttack-2, semantic cache): Qwen3-8B 83.1%, Qwen3-32B 83.8%, DeepSeek-R1-0528 84.6%, Llama-3.1-8B-Instruct 81.0%, Mistral2-7B-Instruct-v0.2 81.4%. The authors state variance is below 2.0.
- Similarity threshold (Figure 3): τ from 0.75 to 0.90 in steps of 0.025. The authors state HR and ISR gradually decrease as the threshold increases. The figure annotates τ=0.800 with HR 83.1%, ISR 77.1%. The main text defines ISR as Injection Success Rate; Figure 3's legend writes Invalid Success Rate (ISR). Numerical values for other data points are not given.
- Low results: On industrial interfaces, GA is 12.4% (AWS) and 15.2% (Azure), lower than Table 1's GA. Among salting strategies, Suffix shows the smallest reduction. Off-diagonal transfer is lower than diagonal.
What are some points that can be further explored?
The paper does not have a dedicated limitations section; the Conclusion hopes for the development of collision-resistant caches that can withstand adversarial manipulation.
Limitations and future directions noted by the authors
- Collision-resistant architecture: The Conclusion hopes that future work can develop collision-resistant cache architectures that withstand adversarial manipulation in production environments. The paper has no dedicated Limitations, Discussion, or Future Work sections, and it does not frame any experimental failure as a limitation of the method itself.
- Implementation-level vulnerabilities: The Conclusion states that the current semantic cache implementation is optimized for performance while introducing critical vulnerabilities. The abstract states that the discussed mitigation strategies still face an ongoing trade-off between cache efficiency and robustness. These two sentences are conclusions about the cache design, not a list of experimental gaps.
Experimental coverage
- Two caches are evaluated: GPTCache (with τ=0.8 in Appendix B) and the authors' reimplementation of SemShareKV; the main experimental backend is Qwen3-8B, with a maximum search step limit of 1000.
- RQ1 draws 50 benign queries from Natural Questions, with the malicious side being SC-IPI (4185 entries) constructed by GPT-5.2; additionally, only HR is reported on AWS Bedrock and Azure API Management.
- The transfer experiment is a 4×4 combination of four embedding models. Backend sensitivity additionally tests Qwen3-32B, DeepSeek-R1-0528, Llama-3.1-8B-Instruct, and Mistral2-7B-Instruct-v0.2, with temperature fixed at 0.
- Defense evaluations include three types of salting (plus the Best row in the table), insertion-time perplexity screening, and per-user cache isolation. The latter two do not have HR/ISR reductions with the same measurement basis as Table 1. The financial case uses Qwen3-32B and GPTCache, without numerical metrics.
- The paper does not report λ, α, TTL duration, the number of validator calibration queries, the review method for ISR or human agreement, the number of agent experiment trials, or the number of repetitions for each table.
Summarize the main content of the paper
CacheAttack hijacks semantic caches and agent tool calls through key collisions; the authors state this is a risk arising from design trade-offs.
The authors study key collisions in multi-tenant LLM semantic caches and propose a black-box framework, CacheAttack.
- Problem: Semantic keys are locality-preserving fuzzy hashes, conflicting with the avalanche effect. Attackers do not modify cache values, but only cause queries with malicious instructions to collide with benign queries on similarity thresholds or LSH partitions, making victims reuse attacker-implanted responses.
- Method: The generator uses GCG-style search to optimize discrete suffixes, with a perplexity term added. The verifier uses Gaussian MAP on log latency to determine hits. CacheAttack-1 verifies directly on the target, subject to TTL constraints; CacheAttack-2 first filters on a proxy, with the target only for final verification. Main setting τ=0.8, search step limit 1000.
- Response hijacking: With Qwen3-8B, e5 cache, bge proxy, and 50 NQ samples, CacheAttack-1 achieves HR of 86.9% and ISR of 81.1% on semantic cache; on semantic KV cache, 85.8% and 83.0% (Table 1). The abstract reports a hit rate of 86%. On Azure, CacheAttack-1 achieves HR of 88.3%, and on AWS Bedrock, 80.6% (Table 2).
- Agents, transfer, and mitigation: On semantic cache, tool hijacking HR is 90.6%, ΔTSR is 84.5, and ΔAcc is 83.8 (Table 3). Diagonal HR for four embedding models is 93.4%, 92.1%, 94.0%, 93.1% (Table 4). After salting, the Best row on semantic cache shows ΔHR of 21.0 percentage points and ΔISR of 25.4 percentage points (Table 5).
- Authors' conclusion: The authors state that key collisions are an inherent integrity risk of semantic caches, not an anomaly; implementations optimized for hit rates introduce this vulnerability. Salting, perplexity screening, and per-user isolation do not eliminate the trade-off between efficiency and collision resistance. The authors hope for future collision-resistant cache architectures that can withstand adversarial manipulation.