Famous bugsIncident report
Heartbleed: the bug that bled the web, and the week that patched it
A missing length check in OpenSSL leaked server memory for two years; a small patch and months of new keys fixed it.

In April 2014 the world learned that OpenSSL, the code that secured a large share of the web's encrypted connections, had been quietly leaking server memory for two years. A missing length check let anyone ask a server for up to 64 kilobytes of whatever happened to sit next to a tiny message, and that memory could hold passwords, session cookies and even the server's private key. OpenSSL published the fix on the same day the world heard about the bug, and the hard part came after: patching, revoking and reissuing certificates across the internet.
When: April 2014 Hit: An estimated 17% of secure web servers, about half a million sites Way in: A missing length check in OpenSSL's heartbeat code Found by: Neel Mehta (Google) and Codenomicon, independently Fixed by: OpenSSL 1.0.1g (CVE-2014-0160) Time to fix: 6 days from first report to public patch
What happened
OpenSSL is a free, open-source library that most web servers of the time used to speak TLS, the protocol behind the padlock in your browser. In early 2012 the TLS standards added a small feature called the heartbeat, described in RFC 6520. A heartbeat lets one side of a connection send a short message and get the same message echoed back, a cheap way to check that the other side is still there without setting up a new connection.
OpenSSL added support for heartbeats in version 1.0.1, released in March 2012. The code had passed review and looked routine. It was not. For two years every server running OpenSSL 1.0.1 through 1.0.1f would hand out pieces of its own memory to anyone who asked in the right way, and it left no trace in ordinary logs.
When the bug went public on 7 April 2014, the internet survey company Netcraft estimated that around 17% of the secure web servers it tracked, roughly half a million sites with trusted certificates, had the heartbeat feature switched on and were likely exposed. Email servers, VPNs and devices that embedded OpenSSL were exposed too.
How it worked
A heartbeat request says, in effect, "here is a message, and it is this many bytes long; please send it back." The bug was that OpenSSL believed the stated length without checking it against the message it had actually received.
So a request could carry a one-byte message while claiming it was 64 kilobytes long. OpenSSL would dutifully copy 64 kilobytes starting at that one byte, and send back the message plus whatever lay beyond it in the server's memory. Each request leaked a different slice. Repeat it enough and an attacker could gather fragments of other users' requests, login details and cookies.
The worst case was the server's private key, the secret that proves a site is who it says it is. At first some experts doubted a key could realistically be pulled out this way. To settle it, Cloudflare set up a deliberately vulnerable server and challenged the public to steal its key. Within about a day, more than one person had done so. That result is why the fix could not stop at patching: every exposed site had to assume its key was gone.
The flaw was a classic one, an unchecked length in memory-unsafe C code. It sat in a project that a huge share of the internet depended on and that, at the time, had very few paid developers.
How it was discovered
Heartbleed was found twice, in the same week, by two teams using opposite methods.
Neel Mehta of Google's security team found it by reading the code. He was reviewing OpenSSL's source by hand, the slow way of looking for mistakes, and spotted that the heartbeat handler copied as many bytes as the request claimed without checking. He reported it privately to OpenSSL.
Codenomicon's engineers found it by testing behaviour. They were improving the automated security testing tools the company sells, which throw unusual and malformed messages at software to see what breaks. Then they attacked their own servers from the outside, as any stranger could, and found they could read back their own private keys, user names, passwords and private messages. Nothing in their logs showed the attack had happened.
That last finding is why nobody had noticed Heartbleed in two years: a heartbeat request looked normal and left no trace. Once it was public, security vendors wrote network rules that flag heartbeat replies far larger than the request, so the attack could at least be seen from then on.
The timeline
2012-03-14 · OpenSSL 1.0.1 ships with the heartbeat code
The heartbeat feature arrives in a major release, and with it the missing length check. Nobody notices for two years.
2014-04-01 · Google's Neel Mehta reports the bug to OpenSSL
A Google security researcher finds the flaw while reviewing OpenSSL's code and reports it privately so a fix can be prepared before the public hears about it.
2014-04-03 · Codenomicon finds the same bug on its own
Engineers at the Finnish security company Codenomicon find the flaw independently while testing their own products and report it to Finland's national cyber security centre. They also give it a name, Heartbleed, a logo and a website explaining it in plain language.
2014-04-07 · OpenSSL publishes the advisory and version 1.0.1g
OpenSSL announces CVE-2014-0160 and ships the fixed version the same day. Admins who cannot upgrade at once are told they can rebuild OpenSSL with the heartbeat feature turned off.
How it was fixed
The code change itself was small. OpenSSL 1.0.1g checks that a heartbeat message is really as long as it claims to be, and silently drops any request that lies. Operating system vendors pushed updated packages within hours and days.
Patching only stopped new leaks, though. Because nobody could know what had already been taken, the advice to site owners had three steps: patch OpenSSL, get a new certificate with a new private key, and revoke the old one. Then users were asked to change passwords on sites that had been exposed, but only after those sites had patched, since changing a password on a still-leaking server would leak the new one.
Certificate authorities handled a surge of reissues and revocations in the weeks that followed. The patch took days to arrive. Cleaning up after it took months.
What changed after
Heartbleed made the funding gap behind critical open-source software impossible to ignore. Within weeks the Linux Foundation launched the Core Infrastructure Initiative, backed by large technology companies, to pay for work on under-resourced projects. OpenSSL was among the first it funded, and the project went on to hire staff, adopt a formal security policy and audit its code.
The bug also led to new versions of OpenSSL's code. The OpenBSD developers forked it into LibreSSL and removed large amounts of old code. Google created BoringSSL for its own products. Both aimed for a smaller, easier-to-review codebase.
Its name and logo changed how flaws are announced. Giving a serious bug a memorable name and a plain explanation helped Heartbleed reach people who never read security advisories, and many later disclosures followed the same pattern.
Lessons that still apply
- Know what you depend on. Many organisations had to scramble to find every device and service that bundled OpenSSL. An up-to-date inventory of your software dependencies turns a crisis into a checklist.
- Patch, then rotate secrets. When a flaw may have exposed secrets, fixing it is only half the job. Keys, certificates and passwords that were exposed need replacing.
- Never trust a length you were told. Input that describes itself must be checked against reality. This is still one of the most common causes of memory bugs.
- Fund what you rely on. If your product depends on an open-source project, supporting its maintainers is cheaper than an emergency.
Sources
- OpenSSL Security Advisory, 7 April 2014
- NVD entry for CVE-2014-0160, National Institute of Standards and Technology
- The Heartbleed Bug, Codenomicon, April 2014
- Half a million widely trusted websites vulnerable to Heartbleed bug, Netcraft, 8 April 2014
- RFC 6520: TLS and DTLS Heartbeat Extension, IETF, February 2012
- The Results of the CloudFlare Challenge, Cloudflare, April 2014
- LibreSSL project
The fix → One unchecked length, one small patch, and months of new keys for half a million sites.