Vulnerability7 Apr 2014

Heartbleed (CVE-2014-0160)

A missing length check let anyone ask an OpenSSL server to echo back up to 64 KB of its memory, private keys included.

Severity
History books
Difficulty
beginner
Companies
OpenSSL, Google, Codenomicon
Tech
OpenSSL, TLS, C, Memory safety
Root cause
memory safety, unpatched flaw

The story

Quick (1 min)

On 7 April 2014, the world learned about Heartbleed, a bug in OpenSSL, the software that secures a huge share of the web's encrypted (HTTPS) connections.

TLS has a "heartbeat" feature: one side sends a message like "say back these 5 letters: HELLO" to check the connection is alive. OpenSSL trusted the number the sender claimed instead of checking the real message length. An attacker could send "say back these 64,000 letters: HI", and the server would send back HI plus whatever happened to be next in its memory.

That memory could hold passwords, session cookies, and even the server's private key. Around 17% of trusted secure web servers (about half a million) were thought to be vulnerable.

The lesson: never trust a length that comes from the network. Check it against what you actually received.

Keep reading to the end to earn XP.Read. XP earned.

Engineer (2 min)

The feature. RFC 6520 (February 2012) added the Heartbeat Extension to TLS and DTLS to keep connections alive without renegotiating. A heartbeat request carries a payload and a payload length; the peer must echo the payload back.

The bug. OpenSSL allocated the response buffer and copied data based on the length field in the request, "without regard to the actual size of that message's payload" (Wikipedia). There was no bounds check, so a request claiming a big length with a tiny payload made OpenSSL read past the payload into adjacent heap memory. That's a buffer over-read of up to 64 KB per heartbeat, repeatable as often as the attacker likes.

What leaked. heartbleed.com grouped it into primary key material (server private keys), secondary key material (user credentials), protected content and collateral (memory addresses and the like). With the private key, an attacker could impersonate the server, or decrypt previously recorded traffic if the connection didn't use perfect forward secrecy. It worked against servers and clients, and exploitation left little trace in normal logs.

Versions. OpenSSL 1.0.1 through 1.0.1f. The bug was introduced in December 2011 and released in 1.0.1 on 14 March 2012. The fix, 1.0.1g, came out on 7 April 2014 and silently discards heartbeat requests whose claimed length exceeds the record.

Discovery. Found independently by Neel Mehta of Google's security team (reported to OpenSSL on 1 April 2014) and by Codenomicon, which named it and launched heartbleed.com.

Interview takeaway: validate attacker-controlled lengths, use fuzzing and robustness tests, and remember that patching isn't enough. Keys and certificates had to be rotated and revoked.

Keep reading to the end to earn XP.Read. XP earned.

Deep dive (2 min)

Timeline

  • 2011: Robin Seggelmann implements the Heartbeat Extension for OpenSSL. An OpenSSL core developer reviews it (Wikipedia).
  • December 2011: the bug enters OpenSSL's code (heartbleed.com).
  • 14 March 2012: OpenSSL 1.0.1 ships with the bug. Heartbleed.com notes rapid adoption, partly because 1.0.1 brought TLS 1.1 and 1.2.
  • 1 April 2014, 11:09 UTC: Neel Mehta privately reports it to OpenSSL (Wikipedia, citing OpenSSL's Mark J. Cox). Codenomicon finds it independently around 3 April.
  • 7 April 2014: fix applied and OpenSSL 1.0.1g released. CVE-2014-0160 published (NVD).
  • 8 April 2014: the Canada Revenue Agency says about 900 social insurance numbers were stolen through Heartbleed during a 6-hour window (Wikipedia).
  • 11 April 2014: per Netcraft, about 30,000 of 500,000+ possibly compromised certificates had been reissued, and fewer revoked (Wikipedia).
  • 24 April 2014: the Linux Foundation announces the Core Infrastructure Initiative to fund critical open-source projects such as OpenSSL (Wikipedia).
  • 21 June 2014: 309,197 public web servers still vulnerable (Wikipedia).
  • August 2014: Community Health Systems discloses a breach of 4.5 million patient records, enabled by Heartbleed (Wikipedia).
  • 4 May 2022: added to CISA's Known Exploited Vulnerabilities catalogue (NVD).

The flaw in one sentence

"The (1) TLS and (2) DTLS implementations in OpenSSL 1.0.1 before 1.0.1g do not properly handle Heartbeat Extension packets, which allows remote attackers to obtain sensitive information from process memory via crafted packets that trigger a buffer over-read, as demonstrated by reading private keys." (NVD)

Why it hit so hard

  • OpenSSL was everywhere, including in Debian Wheezy, Ubuntu 12.04.4 LTS, CentOS 6.5 and Fedora 18 (heartbleed.com).
  • It was hard to detect exploitation after the fact.
  • Recovery meant more than patching: revoke and reissue certificates, rotate keys, and reset user passwords and sessions.

The funding question

The author said he missed validating a length variable, and that OpenSSL "is not reviewed by enough people" (Wikipedia). Heartbleed became the defining example of critical internet infrastructure maintained by very few people. David A. Wheeler argued that thorough robustness testing (checking that invalid inputs fail) would have been the most efficient way to catch it.

Severity

NVD rates CVE-2014-0160 at CVSS 3.1 base score 7.5.

Keep reading to the end to earn XP.Read. XP earned.

Failure replay

Step by step, what broke and what it hit next.

  1. Mar 2012
    OpenSSL 1.0.1degraded

    OpenSSL ships the Heartbeat Extension with no check that the claimed payload length matches the real one.

    Affects: Web servers

  2. 2012–2014
    Web serversdegraded

    Distributions adopt 1.0.1 quickly for TLS 1.2. About 17% of trusted HTTPS servers end up vulnerable.

  3. Attack
    Attackercompromised

    The attacker sends a heartbeat with a 1-byte payload but claims a length of up to 64 KB.

    Affects: Web servers

  4. Attack
    Web serverscompromised

    OpenSSL copies 64 KB starting at the payload, echoing back adjacent heap memory with keys, cookies and passwords.

    Affects: Attacker

  5. Apr 1, 2014
    OpenSSL 1.0.1degraded

    Google's Neel Mehta privately reports the bug. Codenomicon finds it independently days later.

  6. Apr 7, 2014
    OpenSSL 1.0.1recovering

    Version 1.0.1g adds the bounds check and is released with the public disclosure.

    Affects: Web servers

  7. Weeks after
    Usersrecovering

    Sites patch, reissue certificates, rotate keys and ask users to change passwords. Some, like the Canada Revenue Agency, were exploited first.

Impact

Who was affected
Servers and clients using OpenSSL 1.0.1–1.0.1f; around 17% (about half a million) of trusted secure web servers at disclosure. Known exploitation included the Canada Revenue Agency and Community Health Systems.
How long
Vulnerable code was in released OpenSSL for about two years (March 2012 to April 2014); hundreds of thousands of servers stayed unpatched months later.
Cost
not disclosed

Lessons

  • Never trust a length field from the network; check it against the bytes actually received.
  • Memory-unsafe code handling untrusted input needs fuzzing and robustness tests.
  • Patching isn't enough after a key-leaking bug; revoke certificates, rotate keys, reset sessions.
  • Perfect forward secrecy limits damage when long-term keys leak.
  • Critical open-source infrastructure needs funding and reviewers.

Quiz

  1. What did the Heartbleed bug allow an attacker to do?

    Check answer

    Read up to 64 KB of the target's memory per heartbeat request. It was a buffer over-read that leaked adjacent memory, potentially including private keys and passwords.

  2. What was the root coding mistake?

    Check answer

    Trusting the payload length field in the request without checking the real payload size. OpenSSL used the attacker-supplied length to decide how much to copy back.

  3. Which OpenSSL version fixed Heartbleed?

    Check answer

    1.0.1g. 1.0.1 through 1.0.1f were vulnerable; 1.0.1g, released on 7 April 2014, fixed it.

  4. Why was patching alone not enough?

    Check answer

    Secrets such as private keys may already have leaked, so certificates and keys had to be revoked and reissued. Patching stops new leaks, but anything already leaked stays compromised until rotated.

Interview prep

Try answering out loud before you open the model answer.

  1. security

    Explain the Heartbleed bug at the code level and how you would prevent this class of vulnerability.

    Show model answer

    The heartbeat handler read a payload length from the request and copied that many bytes into the response, without checking it against the actual record length. A tiny payload with a claimed length of 64 KB caused a buffer over-read that leaked adjacent heap memory. The fix was a bounds check that discards requests where the claimed length exceeds the record. Prevention: validate all length fields from untrusted input, use safer abstractions or memory-safe languages for parsers, fuzz protocol handlers, write robustness tests that confirm invalid input is rejected, and minimise the attack surface by disabling rarely needed features like heartbeat.

    A strong answer hits:

    • Trusted attacker-supplied length, so a buffer over-read
    • Bounds check fix
    • Fuzzing and robustness testing
    • Memory-safe parsing and reduced attack surface
  2. system design

    A critical bug may have leaked your servers' TLS private keys. Walk through your incident response.

    Show model answer

    Patch first so no more leaks happen. Assume the keys are compromised: generate new key pairs, get new certificates, and revoke the old ones. Rotate other secrets that may have been in memory (session tokens, API keys, database credentials) and invalidate user sessions; prompt password resets where appropriate. Check whether you used forward secrecy, which determines whether recorded past traffic is exposed. Communicate with users and track remaining vulnerable hosts with scanning. Heartbleed showed many sites patched but never revoked certificates.

    A strong answer hits:

    • Patch, then rotate keys and revoke certificates
    • Rotate other in-memory secrets and sessions
    • Assess forward secrecy for past traffic
    • Scan for stragglers and communicate
  3. behavioural

    Heartbleed was in widely used open-source software with few maintainers. How should a company that depends on such projects manage that risk?

    Show model answer

    Keep an inventory of critical dependencies (an SBOM) and assess their health: maintainer count, funding, security process. Contribute back with code review, fuzzing infrastructure, funding or staff time; the Core Infrastructure Initiative was the industry's response to Heartbleed. Subscribe to security advisories and have a fast patching pipeline. Reduce exposure by disabling unused features.

    A strong answer hits:

    • Dependency inventory and health assessment
    • Contribute funding, review and fuzzing
    • Fast patch pipeline
    • Disable unused features

Go deeper