KHAGAN AYDIN

OWASP 2013 A6: Sensitive Data Exposure

The cheapest data to protect is the data you decided not to keep.

· 11 min read

Sensitive Data Exposure is a security vulnerability in which an application holds data that would hurt a person if it leaked, and does not protect it well enough where it is stored or while it travels. It is number six on the 2013 OWASP Top 10, and it is the one item on the list that is not really a single bug. It is a family of mistakes about one question: when your application holds something that would hurt a person if it leaked, is it protected in a way that still works after someone has already gotten in?

Most of the list is about keeping attackers out. This item assumes they got in anyway, or that they are sitting on the same coffee shop network as your user, and asks what they walk away with. Injection and access control failures are how the door opens. Sensitive Data Exposure is why the room behind the door is worth robbing. The 2013 edition merged two older items, Insecure Cryptographic Storage and Insufficient Transport Layer Protection, into this one, because developers never treated them as separate problems. You either protect data where it rests and where it moves, or you do not.

The two places data lives

Data is either sitting still (at rest: in a database, a backup, a log file, a browser cache) or it is moving (in transit: between the browser and your server, or between your servers). Both need protection, and the protections are different.

At rest means encryption and, for passwords, hashing. The word encryption gets used for both, which causes real harm, so I will be exact. Encryption is reversible: you hold a key, and with the key you can read the data back. You use it for data you need to read again, like a stored card number or a social security number. Hashing is one-way: there is no key and no way back, only the ability to check whether a new input matches. You use it for passwords, because you never need the original password, only to confirm the one typed at login.

In transit means Transport Layer Security (TLS), the protocol behind the padlock, the successor to the older Secure Sockets Layer (SSL). It stops anyone between the user and your server from reading or changing the traffic.

Get either wrong and the data is exposed even though nothing in your own code looks broken.

How the data actually leaks

Three everyday paths, none of them exotic.

A user signs in at an airport. If the login form is served over plain HTTP, anyone on the same wireless network reads the password out of the air with free software. They do not attack your server at all. They attack the hop between the user and you.

The site uses HTTPS, but the attacker sits in the middle and quietly rewrites every https:// link to http:// as the pages pass through. The browser never gets the chance to encrypt, the user sees an ordinary page with no warning, and every form they submit arrives in clear text. This is called SSL stripping, and a tool to do it was demonstrated at a security conference in 2009; in a single day on one network it collected 254 passwords for mail, payment and social accounts. It still works against any site that does not force encryption.

Someone pulls your users table through an injection bug. Now the only thing between them and every account is how you stored the passwords. If you hashed them with a fast function, they will crack most of the table on a single graphics card over a weekend. If you stored them in a way that can be reversed, the weekend is not even necessary.

Three cases, three different failures

Adobe, October 2013. Attackers took a backup file holding the records of about 38 million active accounts, part of a dump of more than 150 million records that soon circulated. Adobe had encrypted the passwords instead of hashing them: Triple DES, a reversible cipher, under a single key, in a mode (electronic codebook) that gives identical passwords an identical encrypted value. That choice was wrong before the key was ever at risk. A reversible cipher means the plaintext is one stolen key away, and here the colliding values and the password hints stored in clear text beside them let researchers read off the common passwords with no key at all. The root cause was using encryption where a one-way hash belonged, for data no one ever needs to read back.

Anthem, disclosed February 2015. A health insurer reported that attackers reached a database holding about 78.8 million records: names, birth dates, addresses, and social security numbers. The attackers got in using the stolen credentials of administrators, then read the data, which was not encrypted at rest. Encryption at rest would not have stopped a thief holding a valid administrator login, but the records of tens of millions of people sat in plain readable form. The root cause was sensitive identity data stored without encryption, where one compromised account exposed all of it.

Ashley Madison, mid-2015. The site was breached in July 2015 and the data dumped in August. The main passwords were hashed with bcrypt, a slow function, at a reasonable work setting. That should have been the end of it. But the same code base also built a second token for each account, a login key, as a plain MD5 hash, and the code lowercased the values that went into it. In September 2015 a password cracking group noticed that this fast, lowercased token existed alongside the strong one for roughly 15 million accounts, attacked the weak token instead of the strong hash, and recovered its input, then corrected the case against the bcrypt hash. They announced about 11 million passwords recovered. The strong hashing was real, and one leftover fast hash on the side made it irrelevant. The root cause: a second, weaker representation of the same secret. An attacker always hits the weakest copy.

The pattern across all three: the company thought it had protected the data, and a wrong algorithm, a wrong mode, or a forgotten second copy undid the protection.

Storing passwords so a stolen table is useless

The mistake is using a fast hash. Functions like MD5 and the SHA family are built to be fast, which is exactly what you do not want for a password, because fast for you is fast for the attacker.

Vulnerable code

<?php
// PHP: fast, and salted or not it still falls to a GPU
$hash = hash('sha256', $_POST['password']);
// store $hash

A fast hash lets an attacker try billions of guesses a second against a stolen table. A salt (a unique random value per user, stored alongside the hash) stops precomputed lookup tables and stops two identical passwords from sharing a hash, but it does nothing about raw guessing speed. Salt is necessary and not sufficient.

The fix is a function built to be deliberately slow, with a cost setting you raise as hardware improves: bcrypt, scrypt, or PBKDF2 (Password-Based Key Derivation Function 2). They salt for you and they make each guess expensive.

Fixed code

<?php
// PHP 5.5+: bcrypt via the built-in password API, salt handled for you
$hash = password_hash($_POST['password'], PASSWORD_DEFAULT, ['cost' => 12]);
// store $hash as-is; it already contains the algorithm, cost and salt

// at login:
if (password_verify($_POST['password'], $hash)) {
    // and transparently upgrade old hashes to the current cost
    if (password_needs_rehash($hash, PASSWORD_DEFAULT, ['cost' => 12])) {
        $newHash = password_hash($_POST['password'], PASSWORD_DEFAULT, ['cost' => 12]);
        // store $newHash
    }
}

In Java the same idea with PBKDF2 from the standard library:

SecureRandom random = new SecureRandom();
byte[] salt = new byte[16];
random.nextBytes(salt);

KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 100000, 256);
SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
byte[] hash = f.generateSecret(spec).getEncoded();
// store salt, the iteration count (100000), and hash

The one rule that would have saved Ashley Madison: a password gets hashed one way, in one place, and never has a second, weaker representation anywhere in the system.

Protecting data in transit

Serve the whole site over HTTPS, not just the login form. A session cookie sent once over plain HTTP is a stolen session, and a login page is useless if the next page leaks the cookie that login produced.

Then tell the browser to refuse plain HTTP for your domain, which is how you shut down SSL stripping. The header is HTTP Strict Transport Security (HSTS), standardised in late 2012 and supported by every current major browser:

Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

Once a browser sees this header, it will not make a plain HTTP request to your domain for a year, even if the user types http:// or clicks a stripped link. There is a catch worth knowing: the browser only learns this after its first successful HTTPS visit, so the very first request is still exposed. The preload directive closes that gap by letting you submit your domain to a list that browsers ship with, so the rule is known before the first visit.

The server side has to be configured as well, and in 2015 that means turning old, broken protocols off. SSL 3.0 was finished off by the POODLE attack in October 2014 (CVE-2014-3566) and formally deprecated by the standards body in June 2015. RC4, an old encryption method with known weaknesses, was prohibited in February 2015. Export-grade ciphers, the deliberately weak ones left over from 1990s regulations, were shown that same year to be forced onto modern connections by the FREAK and Logjam attacks, so they must be off too.

A server configuration appropriate for 2015 (nginx):

# Only modern protocols. No SSLv2, no SSLv3.
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

# Prefer forward-secret, authenticated ciphers. No RC4, no export, no plain DES.
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK';

# Logjam: use your own strong Diffie-Hellman group, not a shared 1024-bit default.
# Generate once with: openssl dhparam -out dhparam.pem 2048
ssl_dhparam /etc/nginx/dhparam.pem;

Why the usual fixes fall short

HTTPS on the login page only. A classic finding. The password is protected, the session cookie that the login hands back is not, and the attacker takes the cookie instead of the password and is now logged in as the user. Protect the whole authenticated site, or protect nothing.

Encryption at rest without key management. Encrypting the database and then leaving the key in a config file in the same web root, or in the same backup, protects against a stolen hard drive and nothing else. The Anthem caveat applies in reverse here too: if the key travels with the data, encryption is theatre. The key belongs somewhere the application server can reach at runtime but a database dump or a code leak cannot: a separate secrets service or a hardware module, with its own access control and its own audit log.

Hashing, but with the wrong tool. A fast hash with a salt feels like diligence and is not. The salt defeats lookup tables; it does not slow down guessing. Only a deliberately slow function does that.

One strong protection and one weak copy. The Ashley Madison failure. It does not matter how good your main hash is if the same secret exists somewhere else in a weaker form: an old column, a cache, a log line, a password reset token built the lazy way.

Test your own application

Walk the data, not the code.

List what you store that would hurt someone if it leaked: passwords, card numbers, government identifiers, health data, anything private. For each, ask where else a copy lives: backups, logs, analytics, a search index, a cache, a report emailed every morning. The copies are where exposure hides.

Check how passwords are stored. Pull one row. If the hash is 32 hex characters it is MD5; 40 is SHA-1; both are wrong. A bcrypt hash starts with $2. If you cannot tell, that is itself a finding.

Check transport. From a machine on a different network, request the plain HTTP version of an authenticated page and watch whether the session cookie comes back without the Secure flag. Confirm the Strict-Transport-Security header is present on every response. Point a server scanner at the site and confirm SSLv3, RC4 and export ciphers are all refused.

Look for data in the wrong places. Grep your logs for things that look like card numbers or passwords. Submit a sensitive field and then check whether the browser offers to autocomplete it next time, whether it appears in a URL (and therefore in the browser history, the server log, and the Referer header sent to the next site), and whether the back button after logout still shows a private page from the cache.

The point

Sensitive Data Exposure is the item that punishes optimism. Every other bug on the list is a door; this is whether the valuables were in a safe or on the table. The defenses are known and boring: hash passwords with a slow function, encrypt what you must keep and keep the keys apart from the data, force TLS everywhere with HSTS, and turn off the broken protocols. The hard part is not any one of them. It is the copy you forgot, and the single best move against that is upstream of all the cryptography: do not store what you do not need. The card number you never kept cannot leak, the password you hash once and never duplicate has no weaker twin to attack, and the field you chose not to log is not in the breach. For the storage you cannot avoid, the discipline is the same as with injection: make the safe way the only way, and check that nothing quietly made a second copy.

Checklist

  • Hash passwords with bcrypt, scrypt or PBKDF2 at a cost you raise over time. Never a bare fast hash.
  • Make sure no second, weaker copy of any secret exists: old columns, caches, tokens, logs.
  • Serve the whole authenticated site over HTTPS, not just the login page.
  • Send the HSTS header on every response, and preload your domain.
  • Turn off SSLv3, RC4 and export ciphers; use your own 2048-bit Diffie-Hellman group.
  • Encrypt sensitive data at rest and keep the key somewhere a database dump cannot reach.
  • Keep sensitive values out of URLs, logs, caches and autocomplete.
  • For every field: decide whether you need to store it at all. The safest data is the data you never kept.