Articles / Security

  • tls
  • traffic-analysis
  • wifi
  • privacy
  • wireshark
  • go

What TLS Record Sizes Tell Someone Watching Your Wi-Fi

Encryption hides what you said, not how long it was. Anyone sniffing your Wi-Fi sees every TLS record's length, because the length sits in a five-byte header sent in the clear. With the usual AEAD ciphers there is no block padding, so the length is exact to the byte.

That sounds minor. It isn't, and you can see it for yourself in about a minute.

Look at the records yourself

Capture a short HTTPS session, then list just the record lengths and directions:

sudo tcpdump -i wlan0 -w cap.pcap 'tcp port 443' &
curl -s https://example.com/ > /dev/null
# stop tcpdump, then:
tshark -r cap.pcap -Y 'tls.record.length' \
  -T fields -e frame.time_relative -e ip.src -e tls.record.length

You get a column of numbers. No keys, no decryption. That column is the observer's whole view of the conversation once the handshake is over.

Where the bytes come from

In TLS 1.3 an encrypted record is built like this:

  • a 5-byte header (type, legacy version, length), unencrypted
  • the plaintext, up to 16384 bytes
  • 1 byte of inner content type, encrypted
  • optional zero padding, encrypted
  • a 16-byte AEAD tag

So the length field is plaintext + 17 + padding. If nobody pads, the observer subtracts 17 and has your plaintext length. The cipher hides the bytes, but the length field is the plaintext length plus a constant.

TLS 1.3 does let a sender add padding. Whether your stack ever does is something to check rather than assume; most defaults I know of send none.

What that length gives away

Single lengths are weak evidence. Patterns across a session are strong:

  • Request size: a long URL, a big cookie or a large POST body all show up as one larger upstream record.
  • Response size: a page with a particular HTML size plus a particular set of images produces a recognisable sequence of downstream bursts.
  • Direction and timing: small up, big down, pause, small up, big down looks like browsing; steady large upstream looks like an upload.
  • Handshake size: the server's certificate chain is encrypted in TLS 1.3, but its length is not, so a long chain looks different from a short one, and a resumed session lacks it altogether.

Website fingerprinting, in plain terms

Researchers have shown for years that a classifier trained on size-and-direction sequences can name which page, out of a known set, someone loaded over an encrypted channel. Accuracy depends heavily on the set size, the site and how much the pages change. It works best on a small, fixed list of sites, such as "is this person reading one of these twenty pages?"

That is a different question from "what is this person reading, in general?", and the honest answer is that real-world accuracy is lower than lab results suggest. Still, an observer needs no cooperation from you and no break in the crypto.

Quick detour: what does the Wi-Fi layer add?

Hang on, doesn't Wi-Fi encryption hide this? Partly. On an open network the observer sees the TLS records directly. On a WPA2 or WPA3 network, other people on the same network may or may not be able to read your frames, depending on the mode. With a shared WPA2 passphrase, someone who knows it and captured your association handshake can decrypt your frames. WPA3-SAE is designed to stop that.

Either way, link-layer encryption adds a fixed overhead per frame, so even a purely radio-level eavesdropper sees frame lengths that track your TLS record lengths. And the Wi-Fi network is only one vantage point: your ISP and anything upstream see the same records.

Compression makes it worse

Length leaks become a direct attack when attacker-controlled data and a secret are compressed together. CRIME and BREACH exploited exactly that: guess a byte of a CSRF token, and a correct guess compresses slightly smaller, so the record is a byte or two shorter. That is why TLS-level compression is switched off in practice, and why response-body compression next to secrets still needs care.

What actually helps

  • Pad responses to buckets, so many different pages produce the same length.
  • Use TLS 1.3 record padding if your library exposes it.
  • Avoid compressing secrets alongside user-controlled input.
  • Route sensitive browsing through something built for this, such as Tor, which uses fixed-size cells.
  • Accept that cover traffic costs bandwidth and that no padding scheme hides timing.

Here is the bucket idea at application level in Go. It rounds a response body up to the next multiple of 1024 bytes, using trailing whitespace that HTML ignores:

package main

import (
	"bytes"
	"net/http"
)

const bucket = 1024

// padHTML pads body with spaces to the next bucket boundary.
// Only safe for formats that ignore trailing whitespace, like HTML.
func padHTML(body []byte) []byte {
	n := (len(body) + bucket - 1) / bucket * bucket
	return append(body, bytes.Repeat([]byte{' '}, n-len(body))...)
}

func handler(w http.ResponseWriter, r *http.Request) {
	body := padHTML([]byte("<html><body>hello</body></html>"))
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	w.Write(body)
}

func main() {
	http.HandleFunc("/", handler)
	http.ListenAndServe(":8080", nil)
}

Two caveats. If the response is compressed afterwards, the padding squashes down and the trick fails, so pad after compression or not at all. And it only hides small differences; a 2 KB page and a 2 MB page still look different. The server listing above omits timeouts and error handling for brevity.

The practical reading

For most people on a coffee-shop network, the realistic exposure is which sites you visit (via SNI and DNS, covered elsewhere on this blog) plus coarse activity: video versus browsing versus upload. Record sizes sharpen that picture rather than reveal your messages. If your threat model includes someone deciding which of a few specific pages you read, then sizes matter, and padding or Tor is the answer rather than more encryption.