OWASP 2017 A2: Broken Authentication
Nobody guesses your password anymore. They already have it.
Broken Authentication is a security vulnerability in how an application proves who someone is, which lets an attacker log in as another user. It is number two on the OWASP Top 10 2017. In the 2013 list it was called Broken Authentication and Session Management, and the shorter name is not cosmetic. Session handling (how a token is stored, rotated and destroyed) is now mostly handled correctly by the framework you already use, and I covered it when the 2013 list was current. The part that still bleeds is the front door: proving who someone is. So the 2017 edition drops “Session Management” from the title and points the whole item at authentication itself.
Something else changed between the two lists, and it is the thing that matters most. In 2013, an attack on a login meant guessing: trying common passwords against one account until one worked. By 2017 that is the slow way. Attackers now hold databases of billions of real username and password pairs, leaked from other sites, and they simply replay them against your login. Your users reuse passwords, so a fraction of those pairs work. This is credential stuffing, and it is the dominant attack on authentication today. It changes what a defense has to do. A system tuned to stop guessing can be wide open to replay.
What the bug really is
Broken authentication is not one flaw, it is every way a login lets the wrong person in or lets the right person be impersonated. The 2017 text lists the common ones: the application permits credential stuffing or automated password guessing, it ships or allows weak and well-known passwords, it hashes passwords badly or not at all, it uses weak account recovery, it exposes the session token in the URL, or it has no multi-factor option. Underneath them all is one question: when a request claims to be a given user, what actually stops a stranger from making that claim?
How credential stuffing works
The attacker starts with a file of credentials from some other breach, often tens or hundreds of millions of pairs. They point automated tools at your login and try each pair. They do not try many passwords against one account, which is what lockout and classic rate limiting were built to catch. They try one password against each of a million accounts, spread across thousands of addresses so no single source looks busy. Every pair that works becomes an account they own on your site, to drain, resell or use for fraud.
Two real cases show the shape of it.
In February 2016, Chinese authorities described an attack on the shopping site Taobao, run by Alibaba. Attackers had obtained a database of about 99 million username and password pairs from elsewhere and, using Alibaba’s own cloud service, replayed them against Taobao’s login from mid-October to November 2015. About 20.6 million of those usernames also had Taobao accounts, so the attackers aimed the matching passwords at them. Alibaba said it detected and blocked the bulk of the attempts, but the accounts it did not block were taken with no flaw in Taobao’s password storage, because the owners had reused a password that had already leaked. Some were used for fraud, such as fake orders to inflate sellers’ rankings.
The second case shows the other end of the same problem: what happens when the authentication secret is not the password at all. Yahoo disclosed in December 2016 that an intruder had obtained its proprietary code and learned to forge the cookies that keep a user logged in. A forged cookie let the attacker enter an account with no password, because to the server the forged token looked exactly like a real session. Yahoo tied some of that activity to the actor behind an earlier theft. Then, on October 3, 2017, Yahoo corrected the scale of its 2013 breach: not one billion accounts, but all three billion. The lesson sits next to the Taobao one. The password is one secret an attacker can replay, and the session token is another. Protect one and leave the other forgeable, and you have protected nothing.
The password rules we were taught are wrong
For years the standard advice was: force a mix of upper case, lower case, digits and symbols, and make everyone change their password every ninety days. In June 2017 the United States standards body published new guidance, NIST Special Publication 800-63B, that retired that advice, and it did so with evidence behind it. Its rules for passwords you have to remember are, in plain terms:
- Do not force periodic password changes. People respond to forced changes by picking a weak base and adding a number, and the ninety-day cycle trains that habit without adding strength. Change a password when there is a reason to believe it was exposed, not on a timer.
- Drop the composition rules. Requiring a symbol and a digit pushes people to
Password1!and does little against an attacker’s cracking tools. - Allow long passwords and the full character set, including spaces, so people can use passphrases. Length is what actually resists cracking.
- Screen new passwords against a list of ones already known to be breached or common, and refuse those. This is the rule that speaks directly to credential stuffing: if the password a user picks is already in a leak, it is already in an attacker’s file.
That last rule is the one most teams still miss, so it is worth building out.
Defenses that hold, and how they fail
Screen against breached and common passwords. When a user sets or changes a password, check it against a local list of known-bad passwords and reject a match. You do not need a service for this. Download a published list of the most common leaked passwords, load it once, and compare.
Vulnerable code
# Python, Flask. Enforces composition rules and nothing else.
import re
def password_ok(pw):
return (len(pw) >= 8
and re.search(r'[A-Z]', pw)
and re.search(r'[a-z]', pw)
and re.search(r'[0-9]', pw))
This accepts Password1, which sits near the top of every leaked-password list, and rejects the strong passphrase correct horse battery staple pine for lacking a digit. It enforces exactly the rules the 2017 guidance threw out.
Fixed code
# Load a breached-password list once at startup.
# Each line is one known-bad password.
with open('breached_passwords.txt', encoding='utf-8', errors='ignore') as f:
BREACHED = frozenset(line.strip() for line in f)
def password_ok(pw):
if len(pw) < 12 or len(pw) > 128:
return False
if pw.lower() in BREACHED:
return False
return True
Longer minimum, generous maximum so passphrases fit, no composition rules, and a refusal of anything already leaked. The failure mode to watch: the list only helps at the moment a password is set. A password that was safe last year and leaks this year is still live in your database. So pair this with the rest.
Rate limit by account and by address, separately. Classic lockout counts failures against one account, which stops guessing but not stuffing, because stuffing makes one attempt per account. So count both ways.
# Pseudocode for the check that runs before verifying a password.
# Two independent counters, each in a short-lived store keyed by a time window.
def allow_attempt(username, ip):
if failures_for(ip) > 100: # one address, many accounts: stuffing
return False
if failures_for(username) > 10: # one account, many tries: guessing
return False
return True
The per-address counter is what catches stuffing. Its failure mode: attackers spread the load across thousands of addresses to keep each one under the threshold, and many real users sit behind one shared address, so set the limit as a slowdown with a widening delay rather than a hard block, and log every failure so a human can see a campaign even when no single counter trips.
A login that does not reveal whether the username exists. If “no such user” and “wrong password” look different, an attacker can confirm which of a million email addresses have accounts here before spending a single password guess.
Vulnerable code
user = find_user(username)
if user is None:
return error('No account with that email') # confirms non-members
if not verify(password, user.password_hash):
return error('Incorrect password') # confirms members
Fixed code
user = find_user(username)
if user is None:
# Hash a dummy value so the response takes the same time either way.
verify(password, DUMMY_HASH)
return error('Email or password is incorrect')
if not verify(password, user.password_hash):
return error('Email or password is incorrect')
One message for both cases, and a dummy hash when the user is missing so the response does not come back faster for unknown accounts. The timing detail is the part people forget: a slow password hash means a real account takes longer to reject than a non-existent one, and that difference alone leaks membership.
Offer multi-factor, and know which kinds are weak. A second factor means a replayed password is not enough on its own. Not all second factors are equal. A code sent by text message (SMS) is far better than nothing, but it can be redirected by tricking a mobile carrier into moving the number to a new device, so treat SMS as the weakest option and prefer an authenticator app or a hardware key where the account is worth protecting.
Treat account recovery as a login, because it is one. The reset flow is a second door into the account, and it is often weaker than the first. Security questions are the worst of it: a mother’s maiden name or a first school is not a secret, it is public record. Send a one-time link to the registered email or phone, make it short-lived and single-use, and never reveal through the reset form whether an address is registered.
How to test your own application
- Try to register or change a password to
Password1and to123456789012. If either is accepted, you are not screening against known-bad passwords. - Submit a login for an address you know does not exist, then a real address with a wrong password. Compare the message and the response time. If either differs, your login confirms which accounts exist.
- Script a hundred logins for a hundred different usernames from one address, each with a wrong password. If the hundredth is treated like the first, nothing is counting per address, and stuffing will run freely.
- Walk the password reset flow and ask what a stranger needs to complete it. If the answer is a fact they could look up, the reset is the weak door.
- Check where the session token lives. If it ever appears in a URL, it leaks into logs, history and referrer headers.
The point
The 2013 list treated authentication and sessions as one problem and assumed the attacker was guessing. The 2017 list splits them and assumes the attacker already has the password, because they usually do. That single assumption rewrites the defenses. Composition rules and ninety-day changes were answers to guessing, and against replay they are theater. The answers that hold are the ones that make a stolen password insufficient: screen out the ones already leaked, slow down replay from a single source, hide which accounts exist, add a second factor, and lock down the reset flow and the session token with the same care as the password itself. Do that and a breach somewhere else stops being a breach here.
Checklist
- Screen new passwords against a local list of breached and common ones. Reject matches.
- Require length, allow passphrases and the full character set, and drop composition rules.
- Do not force periodic password changes. Change on evidence of exposure.
- Rate limit by account and by address separately, as a widening delay, and log every failure.
- Return one message for a bad login, and keep the response time the same whether or not the account exists.
- Offer multi-factor. Prefer an app or hardware key over SMS.
- Make reset links short-lived and single-use, and never use public facts as secret questions.
- Keep the session token out of the URL, rotate it at login, destroy it at logout on the server.