All posts

Shared KV Caching and the Multi-Tenant Inference Security Dilemma

worm's eye-view photography of ceiling
Photo by Joshua Sortino (https://unsplash.com/@sortino) on Unsplash (https://unsplash.com/photos/worms-eye-view-photography-of-ceiling-LqKhnDzSF-8)

The push to reduce Time to First Token (TTFT) and lower compute overhead in large language model (LLM) serving has led infrastructure operators to adopt aggressive state reuse. Key-value (KV) caching, particularly shared prefix caching, skips redundant transformer attention computations across requests that share identical initial tokens. However, implementing these performance optimizations in multi-tenant environments creates cross-tenant data leakage risks when caching layers fail to enforce strict isolation boundaries.

The risks of shared inference state became concrete when Cloudflare disclosed a vulnerability involving prompt data exposure, detailed in Cloudflare’s remediation post. In that incident, optimizations centered on KV cache reuse resulted in cached inference data from one request being exposed across tenant boundaries. (unverified: the exact model architecture, affected customer count, and specific inference engine software version deployed during the incident). The failure demonstrated that memory optimizations inside the inference pipeline can undermine the security guarantees of multi-tenant cloud platforms.

The Mechanics of Inference State Leakage

In traditional web infrastructure, caching operates at the application and HTTP layers. Reverse proxies evaluate explicit request metadata, including Authorization headers, session cookies, and URL paths, before serving cached objects. These access-control checks occur before any application state is resolved.

LLM inference engines handle state differently. A KV cache stores intermediate attention tensors in GPU High Bandwidth Memory (HBM) or system RAM across the layers of a model. During prompt prefill, the engine computes key and value vectors for every token. Because prefill is compute-intensive, modern inference runtimes implement prefix caching: if a new prompt shares tokens with an earlier prompt (such as a common system prompt, formatting wrapper, or boilerplate instructions), the runtime reuses the existing KV tensors instead of recalculating them.

Vulnerabilities arise when the cache lookup index depends solely on token sequences rather than cryptographic tenant identifiers. If Tenant B submits a prompt that matches or extends a cached prefix originating from Tenant A, an insufficiently isolated engine can initialize Tenant B’s generation using Tenant A’s cached KV state. Because transformer attention layers attend back across the entire sequence of cached tokens, the model can generate completions directly derived from Tenant A’s private context.

The Architectural Divide in Multi-Tenant Serving

As practitioners noted in the Hacker News discussion, many popular open-source LLM serving frameworks were originally designed for single-tenant clusters or dedicated enterprise workloads. Multi-tenant isolation was frequently treated as an orchestration concern rather than an engine-level invariant. (unverified: specific default configuration flags in upstream inference frameworks discussed in the thread).

When platform teams deploy these engines behind shared API gateways to service multiple external users, standard multi-tenant assumptions break down:

  1. Stateful GPU Runtimes: Unlike stateless microservices that discard process memory between HTTP requests, an inference engine’s performance depends on keeping GPU memory warm.
  2. Ambiguous Cache Keys: If the cache hashing mechanism only inspects token IDs, it cannot distinguish between public context (such as an open-source system prompt) and confidential context (such as proprietary retrieval-augmented generation data) that happens to share a prefix.
  3. Implicit Cross-Contamination: Even partial prefix overlaps can cause the attention mechanism to pull information from the trailing tokens of an earlier request if boundaries are misaligned or if allocation offsets are improperly tracked in memory pools.

Mitigation and Isolation Paradigms

Securing multi-tenant LLM serving while preserving the performance gains of KV caching requires redesigning how inference runtimes handle memory lifecycle and cache key derivation.

Cryptographic, Tenant-Aware Cache Keys

Inference runtimes cannot use raw token arrays as primary cache keys. Cache lookup hashes must incorporate a composite structure: the tenant ID, security domain or workspace ID, model version, and an explicit visibility scope (public versus private). If a request does not possess the correct authorization context, the lookup must register a cache miss regardless of token similarity.

Architectural Separation of Public and Private Prefixes

Platforms can split KV caching into tiered domains:

Dynamic Eviction and Memory Zeroing

When GPU memory blocks are recycled between different tenant requests, platform runtimes must guarantee that the corresponding KV blocks are fully invalidated and zeroed out before re-allocation. Retaining uncleared memory buffers across execution boundaries creates side-channel risks and direct data exposure if pointers misalign.

As LLM workloads mature from experimental prototypes into mission-critical infrastructure, serving stacks must treat GPU memory and inference cache entries with the same tenant-isolation boundaries historically applied to network routing and file systems. Efficiency optimizations cannot bypass authorization checks.