AIDEFEND in Action AIA-0174 Validated Research

Encrypted AI Streams Can Reveal the Shape of an Assistant’s Answer

Researchers at Ben-Gurion University found that a network observer can see the size and timing of encrypted packets even when HTTPS protects an AI assistant’s reply. If those sizes reveal the lengths of streamed text pieces (tokens), the observer may infer parts of the reply. The researchers demonstrated this token-length side channel on ChatGPT-4 and Microsoft Copilot traffic. In the controlled ChatGPT-4 evaluation, about 27% of the first segments of replies were reconstructed above the study’s high-similarity threshold, a measure of how closely the reconstructed text matched the original.

Privacy LeakageData GovernanceAI Infrastructure
1 applicable AIDEFEND defenses
Source: What Was Your Prompt? A Remote Keylogging Attack on AI Assistants 
Authors: Roy Weiss and colleagues
Original article: Aug 14, 2024

Threat Analysis

  • Encryption hides the words, not the packet sizes. A token is the basic chunk of text a language model generates, often a short word or part of a word. When an AI chat service streams each new token as its own small encrypted network message, someone watching the connection can measure each packet’s byte size and timing to recover the sequence of token lengths. This requires both a network vantage point (such as a shared network or transit path) and a service whose streaming messages mirror token sizes.
  • Another AI model turns those lengths into guessed text. Using the sequence of token lengths (much like knowing the exact letter count of every word in a sentence) plus previously guessed text, the researchers used fine-tuned language models to infer likely replies and topics. When an assistant repeats details from the user’s prompt, those guesses can also reveal information from the prompt itself. Reconstruction accuracy drops across longer replies and varies by topic and service behavior.

Applicable AIDEFEND Defenses (1)

AID-H-006.002
Text, Markup & Structured Output Sanitization and Release Gate
Very High
The service operator can buffer all generated text and release one completed response on every public route, including retries and fallback endpoints. Test from the client-facing network boundary using equal-length benign replies that have different internal token-length patterns, confirming that no generated content leaves early and per-token lengths cannot be read from the traffic. This removes the token-length sequence, while total response size and elapsed time remain observable.

What Defenders Should Do Now

  • Buffer sensitive replies at the final client-facing gateway. For sensitive workflows, hold the generated text until the entire answer is ready and deliver it as one completed response across every public route, including retries and fallback endpoints. Verify from outside the final gateway that no generated bytes leave early; keep in mind that total response size and total wait time still remain visible.
  • Measure streaming mitigations through the real delivery path. If users require live word-by-word streaming, test defenses such as random padding (adding random extra bytes to mask each packet’s true length, as Cloudflare introduced for Workers AI streaming events) or chunk batching (grouping multiple tokens before sending). Run benign test traffic through the actual compression, buffering, gateway, and CDN (content delivery network) path to measure both latency and how much length signal remains at the client. If a relay takes only the model text and builds new events for the browser, upstream padding is lost at that point. For fixed-length events, add the padding at the final emitter, verify the delivery path keeps those events uncompressed, and measure the encrypted packet lengths and timing that are still visible.
  • For self-built apps calling hosted APIs, disable streaming and verify whether private networking is supported. If your own application calls an API that supports returning a complete response in one payload (such as OpenAI’s Responses API with streaming disabled), turn off streaming on sensitive routes and verify the actual client-facing path so per-token lengths are not exposed; this matches the full-response release mechanism above. Where a hosted service explicitly supports private network endpoints (such as Azure OpenAI via Azure Private Link), private connectivity keeps traffic off shared public transit paths; however, consumer and SaaS assistant paths tested in the paper (ChatGPT and Microsoft Copilot) must be verified individually and cannot be assumed to inherit Azure OpenAI’s private-endpoint capability.

Conclusion

AIDEFEND  places the release control on the actual client-facing delivery path. Measuring what leaves the final gateway ensures teams do not mistake internal buffering, HTTPS encryption, or an untested setting for traffic-pattern privacy.

Last updated: