Lion Cipher Lab

Close the Token-Length Side Channel in a Streaming LLM Response

Why it matters

Everyone knows HTTPS hides what you say to an AI assistant. Almost nobody checks what it does not hide. When an assistant streams its answer to you token by token -- the little chunks of text a model generates, arriving one at a time so the reply appears to type itself -- each token is pushed onto the wire in its own small message. Encryption scrambles the CONTENT of that message. It does not change its SIZE. And the size of an encrypted record is the size of the plaintext plus a fixed overhead, so an observer who cannot read a single byte of your conversation can still read off the exact…

What you'll learn

Steps in this lab

  1. The attack in one breath: the model is not attacked, the transport is
  2. Why the length leaks: SSE frames, TLS records and AEAD overhead
  3. Set up: offline, key-free, deterministic
  4. Build the wire model, part 1: framing and the tokenizer (stream.py)
  5. Build the wire model, part 2: the corpus and the observer (stream.py)
  6. Build the wire model, part 3: the metrics, and prove the leak is exact
  7. Stage 1: measure what the length sequence alone reveals (attack.py)
  8. Read Stage 1: the observer wins, and wins early
  9. Stage 2: build and measure the four defenses (defend.py)
  10. Read the table: three of the four obvious defenses disappoint
  11. The combination is the answer -- and it is cheaper than doing nothing
  12. Judgment: what still leaks, where the fix belongs, and the family this joins
  13. What you built -- and the one sentence to keep

Open the full interactive lab →