Course contentsShow
← Security
Lesson 1099 of 3,05223. Web Security - Modern Web AttacksFree lesson

HPACK Header Compression Attacks

Understanding HPACK compression, dynamic table manipulation, and attacks like CRIME that exploit header compression mechanisms.

HPACK Header Compression Attacks

What you'll learn: How attackers exploit HTTP/2's header compression mechanism to leak sensitive information from previous requests.


What is HPACK?

HPACK is the compression algorithm used in HTTP/2 to reduce bandwidth by compressing HTTP headers. Instead of sending full headers repeatedly, HPACK maintains a dynamic table that stores previously seen header name-value pairs. Subsequent requests can reference these entries by index rather than resending the entire header.

Think of it like a shared dictionary between client and server: once you've said "Authorization: Bearer abc123", you can just say "entry #42" next time instead of repeating the whole thing.

The Attack Surface

The compression efficiency creates a security vulnerability. If an attacker can:

  1. Inject chosen content into headers (e.g., via script on a compromised page)
  2. Observe the compressed size of the response
  3. Iteratively guess secrets (like session tokens or cookies)

...they can exploit the fact that matching content compresses better. When their guess matches a real header value in the dynamic table, the compressed size shrinks noticeably.

CRIME and Similar Attacks

CRIME (Compression Ratio Info-leak Made Easy) was the original attack demonstrating this principle against TLS compression. The same concept applies to HPACK:

  • Attacker controls some header content (e.g., via JavaScript making requests)
  • They guess one character at a time of a secret cookie
  • Correct guesses produce smaller compressed payloads
  • By measuring response sizes, they can extract the entire secret

Defense Mechanisms

Modern browsers and servers mitigate this by:

  • Separating compression contexts for different security origins
  • Disabling compression for sensitive headers
  • Limiting what content can be injected into headers

Key Takeaway: HPACK compression creates a side-channel vulnerability where attackers can infer secret header values by observing compressed message sizes, requiring careful isolation of compression contexts to prevent information leakage.