Skip to content
Account takeover Write-up Intermediate

Google 2FA Bug: The Login That Outlived the Password

A pending login state on Google's second-factor page was not invalidated when the password was changed or 2FA was disabled, and its timeout could be renewed by switching verification methods. An attacker with a stolen password could park a login, enable then disable 2FA to stay quiet, and still complete the login after the victim reset the password.

medium.com

Published on medium.com

Bug Bounty

Muhammad Asim Shahzad, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

Google's login flow is a two-step state machine. The first step verifies the password and creates a pending login: the account is known, the password is correct, but the session is not yet real because the second factor is still outstanding. The second step checks the second factor and, if it passes, turns the pending login into a full session.

Researcher Luke Berner looked at what happens to that pending state when the account changes underneath it. Two-factor authentication was often bolted onto login flows years after they were first built, by different teams, so the question of whether the pending state tracks later account changes is a reasonable one. At Google, the answer was that it did not.

AI-generated illustration From the original on medium.com

The write-up is an analytical case study of Berner's public disclosure, not the author's own discovery. Google fixed the issue before Berner's January 2019 write-up, and reproduction details are deliberately left out.

Setup

The report does not describe a lab, accounts, roles, tools or versions. What it does establish as preconditions for the bug are:

  1. An attacker who holds a valid password for the account.
  2. The ability to enable 2FA on that account, park a login on the second-factor page, and then disable 2FA again.
  3. A victim who, on noticing something wrong, resets the password in the belief that this ends the intrusion.

The pending login is the object of interest throughout: a password-verified, second-factor-pending state that exists between the two steps of the login.

Finding it

Berner's insight was structural. 2FA is frequently added to login flows years after those flows were designed, by different teams, so the pending state and the account settings it depends on can drift apart. The question he asked was what happens to a pending login when the password changes or when 2FA is switched off.

At Google, nothing happened to it. Changing the password terminated full sessions but left the pending login untouched. Google stated that pending logins expired after about 20 minutes, but Berner found that switching verification methods renewed that timer. He also found that the second-factor page still accepted a valid code after 2FA had been turned off on the account.

Each of those behaviours on its own looks like a loose end. Together they mean the pending login outlives the account state it was created against.

Exploitation

Step 1: enable 2FA on the account

With a stolen password in hand, the attacker turns on 2FA for the account. This is what makes a second-factor step exist for the pending login to sit on.

Step 2: park a login on the code page

The attacker starts a login with the password, passes the first step, and stops at the second-factor page without completing it. That pending login is now parked.

Step 3: disable 2FA to stay quiet

The attacker switches 2FA back off. The account looks as it did before, so there is less for the victim to notice.

Step 4: the victim resets the password

The victim resets the password and reasonably assumes the attacker is out. Full sessions are terminated by the reset, but the parked pending login is not.

Step 5: the parked login completes

The parked login still completes, producing a real session after the password change and after 2FA was removed.

The report gives no HTTP requests, parameters, headers or responses for any of these steps; the reproduction details are intentionally omitted.

Root cause

The flaw is in the authentication logic. A pending login is an intermediate authentication state, and it was not invalidated by password changes or by 2FA changes. Two supporting behaviours made it worse: the pending login's timeout could be renewed by switching verification methods, and the second-factor page still accepted a valid code after 2FA had been turned off.

The existing defence, terminating sessions on password change, did not stop this because it only covered full sessions, not the pending state. The 20-minute expiry did not stop it either, because switching verification methods renewed the timer. The author's analysis is that the final step failed to re-check the account's current policy.

Impact

Password reset is the standard response to a compromised account, and this bug made that response a false recovery. An attacker holding a stolen password could keep persistence through the reset: enable 2FA, park a login on the code page, disable 2FA to stay quiet, wait for the victim to reset the password, then complete the parked login.

The conditions are specific: the attacker needs the password, needs to be able to toggle 2FA on the account, and needs the pending login to survive until they use it. The report does not publish a severity rating or the bounty amount; it says only that Google confirmed the logic flaw, fixed it and awarded a bounty whose amount is not stated. There is no CVE, as this is a hosted service.

Berner reports the same pattern at Microsoft login, where it was closed as intended, and at Instagram, where it was called theoretical. Cloudflare and Algolia fixed it.

Fix

Google confirmed the logic flaw and fixed it before the January 2019 write-up. The report does not describe Google's actual patch. The author's own analysis of how such bugs should be fixed is:

  1. Bind pending logins to the credential version. Store a password epoch and a 2FA config version with the pending state; any mismatch kills it.
  2. Use an absolute deadline. Switching methods may refresh the UI, never the expiry.
  3. Re-check policy at the final step. If the factor was removed, the old challenge is void.

The author's illustrative completion handler, reproduced as published:

Text
PENDING_MAX_AGE = 10 * 60                     def complete_second_factor(pending_id, code):    p = pending_store.get(pending_id)    if p is None or now() - p.created_at > PENDING_MAX_AGE:        return fail()    user = load_user(p.user_id)    if (p.password_epoch != user.password_epoch                  or p.mfa_version != user.mfa_version                   or not user.mfa_enabled):        pending_store.delete(pending_id)        return fail()    if not verify_factor(user, code):        return fail()    pending_store.delete(pending_id)                       return create_session(user)

It checks the pending login against an absolute age, compares the stored password epoch and MFA version with the user's current values, refuses to proceed if MFA is no longer enabled, and deletes the pending state on any mismatch or on success.

Variants to test

  1. Password change mid-flow. Start a login, pass the password step, then change the password from another session and submit the second factor. A positive result is a completed session created from the pending login after the change.
  2. 2FA removal mid-flow. Park a login on the second-factor page, disable 2FA on the account, then submit a code. A positive result is the code being accepted when the factor no longer exists.
  3. Timer renewal. Park a login and switch verification methods repeatedly. A positive result is the pending login surviving well past the stated expiry window.
  4. Other account settings mid-flow. Change account settings that the pending state should depend on, such as recovery options or email address, and see whether the pending login still completes.
  5. Same pattern at other providers. Repeat the parked-login sequence against other login flows that added 2FA later. A positive result is the same persistence after a password reset, the pattern Berner reports at Microsoft and Instagram and that Cloudflare and Algolia fixed.

The general lesson from the report: every intermediate auth state is a session, so inventory and revoke it; timers that reset on user actions are not timeouts; and account settings should be changed mid-flow during testing.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

What happened, in plain words

Imagine you come home to find a stranger has been in your flat. You change the locks. You feel safe. But the stranger had already wedged a side door open, and changing the front lock did nothing about it. That is roughly the shape of the bug described here.

Researcher Luke Berner found a flaw in Google's login system. When you log in to Google, you do it in two steps: first you type your password, then you type a code from your phone (the second factor). Between those two steps, Google keeps a temporary record that says "this person got the password right, they just have not typed the code yet". The report calls this a pending login.

Berner found that this pending login did not care if the account changed underneath it. If you changed your password, your normal logged-in sessions were thrown out, but the pending login stayed alive. If two-factor authentication was switched off, the code page still accepted a code. And the 20-minute expiry on the pending login could be pushed back by switching verification methods.

Google confirmed the logic flaw, fixed it, and paid a bounty. The amount is not published. The write-up this is based on is an analytical case study of Berner's public disclosure, not the author's own discovery, and it deliberately leaves out the reproduction details. Google fixed the issue before Berner's January 2019 write-up.

AI-generated illustration From the original on medium.com

AI-generated illustration

The words you need first

Before the details, a few everyday ideas. None of these are specific to Google; they are how most modern logins work.

  • Authentication is simply proving who you are. Showing a passport at a border is authentication.
  • A session is the state of being logged in. When you log in, the server gives your browser a small piece of data (often called a cookie or a token) that it can recognise on every later request. Think of it as a wristband at a festival: you show it once at the gate, and after that staff just glance at your wrist. Logging out, or the server cancelling the wristband, is called terminating the session.
  • Two-factor authentication (2FA) means proving who you are with two different things. The password is the first factor (something you know). The second factor is usually a code from your phone or a security key (something you have). Even if someone steals your password, they still need the second thing.
  • A state machine is a system that moves through a fixed set of stages. A vending machine is one: waiting for money, then money inserted, then item selected, then dispensing. A login is also one: not logged in, then password checked, then second factor checked, then logged in.
  • An intermediate state is a stage in the middle of that journey. The pending login is exactly that: the password has been checked, but the journey is not finished.
  • A timeout or expiry is a deadline after which something stops being valid. A parking ticket that is valid for one hour is a timeout. The important detail in this story is whether the clock runs from a fixed start (an absolute deadline) or restarts whenever you do something (a rolling timer).
  • A logic flaw is a bug not in the code crashing, but in the rules the code follows. The program does exactly what it was told; the instructions themselves were wrong.
  • A CVE is a public catalogue number for a known vulnerability, so people can refer to it unambiguously. Hosted services like Google's login often do not get one, because there is no software version for you to patch: the provider fixes it on their side.
  • A bounty is money a company pays a researcher who reports a security bug responsibly instead of exploiting it.

The setup

The report does not describe a lab, accounts, roles, tools or versions. What it does establish as the preconditions for the bug are three things:

  1. An attacker who holds a valid password for the account.
  2. The ability to enable 2FA on that account, park a login on the second-factor page, and then disable 2FA again.
  3. A victim who, on noticing something wrong, resets the password in the belief that this ends the intrusion.

Throughout, the object of interest is the pending login: the password-verified, second-factor-pending state that exists between the two steps of the login.

Finding it

Berner's insight was structural, meaning it was about how the system is put together rather than about a single line of code. Two-factor authentication is frequently added to login flows years after those flows were designed, and by different teams. So the pending state and the account settings it depends on can drift apart, like a building extended by a later architect who never saw the original plans.

The question he asked was simple: what happens to a pending login when the password changes, or when 2FA is switched off?

At Google, the answer was that nothing happened to it. Three behaviours stood out:

  1. Changing the password terminated full sessions but left the pending login untouched.
  2. Google stated that pending logins expired after about 20 minutes, but Berner found that switching verification methods renewed that timer.
  3. The second-factor page still accepted a valid code after 2FA had been turned off on the account.

Each of those behaviours on its own looks like a loose end. Together they mean the pending login outlives the account state it was created against. That is the whole bug in one sentence.

Exploitation

Exploitation here means walking through the steps an attacker would take. The report gives no HTTP requests, parameters, headers or responses for any of these steps; the reproduction details are intentionally omitted. What follows is the sequence of actions, not a recipe.

Step 1: enable 2FA on the account

With a stolen password in hand, the attacker turns on 2FA for the account. Why? Because a second-factor step has to exist before a pending login can sit on it. If 2FA is off, there is no code page to park on. Turning it on creates the stage the attacker needs.

Step 2: park a login on the code page

The attacker starts a login with the password, passes the first step, and stops at the second-factor page without completing it. That pending login is now parked, like leaving a car with the engine running and the keys in it, waiting for someone to come back later.

Step 3: disable 2FA to stay quiet

The attacker switches 2FA back off. The account now looks as it did before, so there is less for the victim to notice. This is the stealth part: the attacker is tidying up the evidence while the parked login waits in the background.

Step 4: the victim resets the password

The victim resets the password and reasonably assumes the attacker is out. Full sessions are terminated by the reset, but the parked pending login is not. This is the moment the bug pays off: the standard recovery action does not recover anything.

Step 5: the parked login completes

The parked login still completes. A real session is produced after the password change and after 2FA was removed. The attacker is back in, and the victim's reset achieved nothing.

Root cause

The flaw is in the authentication logic. A pending login is an intermediate authentication state, and it was not invalidated by password changes or by 2FA changes. Two supporting behaviours made it worse: the pending login's timeout could be renewed by switching verification methods, and the second-factor page still accepted a valid code after 2FA had been turned off.

The existing defence, terminating sessions on password change, did not stop this because it only covered full sessions, not the pending state. The 20-minute expiry did not stop it either, because switching verification methods renewed the timer. The author's analysis is that the final step failed to re-check the account's current policy.

In plain terms: the system checked the rules once, at the start, and never looked again. If the rules changed halfway through, nobody told the pending login.

Impact

Password reset is the standard response to a compromised account, and this bug made that response a false recovery. An attacker holding a stolen password could keep persistence through the reset: enable 2FA, park a login on the code page, disable 2FA to stay quiet, wait for the victim to reset the password, then complete the parked login.

Persistence here means staying in after the victim thinks you are gone. The victim stops looking, so the access can go unnoticed.

The conditions are specific: the attacker needs the password, needs to be able to toggle 2FA on the account, and needs the pending login to survive until they use it. The report does not publish a severity rating or the bounty amount; it says only that Google confirmed the logic flaw, fixed it and awarded a bounty whose amount is not stated. There is no CVE, as this is a hosted service.

Berner reports the same pattern at Microsoft login, where it was closed as intended, and at Instagram, where it was called theoretical. Cloudflare and Algolia fixed it. "Closed as intended" means the company replied that the behaviour was by design, not a bug. "Theoretical" means the company judged it not practically exploitable.

Fix

Google confirmed the logic flaw and fixed it before the January 2019 write-up. The report does not describe Google's actual patch. What follows is the author's own analysis of how such bugs should be fixed, in three rules:

  1. Bind pending logins to the credential version. Store a password epoch and a 2FA config version with the pending state; any mismatch kills it. A password epoch is just a counter that goes up every time the password changes, so the system can tell "this pending login was made under password version 3, but the account is now on version 4".
  2. Use an absolute deadline. Switching methods may refresh the UI, never the expiry. The clock starts once and runs down; clicking around does not top it up.
  3. Re-check policy at the final step. If the factor was removed, the old challenge is void. Before accepting the code, look at the account as it is now, not as it was when the challenge was issued.

The author's illustrative completion handler, reproduced as published:

Text
PENDING_MAX_AGE = 10 * 60                     def complete_second_factor(pending_id, code):    p = pending_store.get(pending_id)    if p is None or now() - p.created_at > PENDING_MAX_AGE:        return fail()    user = load_user(p.user_id)    if (p.password_epoch != user.password_epoch                  or p.mfa_version != user.mfa_version                   or not user.mfa_enabled):        pending_store.delete(pending_id)        return fail()    if not verify_factor(user, code):        return fail()    pending_store.delete(pending_id)                       return create_session(user)

Line by line, in plain words:

  • PENDING_MAX_AGE = 10 * 60 sets the maximum age of a pending login to ten minutes, written as seconds. This is the absolute deadline from rule 2.
  • def complete_second_factor(pending_id, code): starts the function that runs when someone submits a code. It receives the identifier of the pending login and the code they typed.
  • p = pending_store.get(pending_id) looks up the stored pending login. If it does not exist, the next check catches it.
  • if p is None or now() - p.created_at > PENDING_MAX_AGE: asks two questions: is there no pending login, or is it older than the maximum age? If either is true, the next line runs.
  • return fail() refuses the login. This is the expiry check, and it uses the creation time, so nothing the user does can extend it.
  • user = load_user(p.user_id) fetches the account as it is right now, not as it was when the pending login was made. This is what makes the next check possible.
  • if (p.password_epoch != user.password_epoch compares the password version stored with the pending login against the account's current password version. != means "is not equal to".
  • or p.mfa_version != user.mfa_version also fails if the 2FA configuration version has changed.
  • or not user.mfa_enabled): also fails if 2FA is no longer switched on at all. This is rule 3: re-check the policy at the final step.
  • pending_store.delete(pending_id) throws the pending login away on any mismatch, so it cannot be retried.
  • return fail() refuses the login.
  • if not verify_factor(user, code): checks the code itself. If it is wrong, the next line runs.
  • return fail() refuses the login.
  • pending_store.delete(pending_id) removes the pending login on success, so it cannot be reused. A pending login should be single-use.
  • return create_session(user) finally creates the real session. Only now is the user logged in.

In short, the handler checks the pending login against an absolute age, compares the stored password epoch and MFA version with the user's current values, refuses to proceed if MFA is no longer enabled, and deletes the pending state on any mismatch or on success.

Variants to test

If you ever test a login flow, these are the variations worth trying. A positive result means the bug is present.

  1. Password change mid-flow. Start a login, pass the password step, then change the password from another session and submit the second factor. A positive result is a completed session created from the pending login after the change.
  2. 2FA removal mid-flow. Park a login on the second-factor page, disable 2FA on the account, then submit a code. A positive result is the code being accepted when the factor no longer exists.
  3. Timer renewal. Park a login and switch verification methods repeatedly. A positive result is the pending login surviving well past the stated expiry window.
  4. Other account settings mid-flow. Change account settings that the pending state should depend on, such as recovery options or email address, and see whether the pending login still completes.
  5. Same pattern at other providers. Repeat the parked-login sequence against other login flows that added 2FA later. A positive result is the same persistence after a password reset, the pattern Berner reports at Microsoft and Instagram and that Cloudflare and Algolia fixed.

The general lesson from the report: every intermediate auth state is a session, so inventory and revoke it; timers that reset on user actions are not timeouts; and account settings should be changed mid-flow during testing.

Glossary

  • 2FA (two-factor authentication): logging in with two different proofs of identity, usually a password plus a code from your phone.
  • Absolute deadline: an expiry that runs from a fixed start time and cannot be extended by user actions.
  • Authentication: the process of proving who you are.
  • Bounty: money a company pays a researcher for responsibly reporting a security bug.
  • Cookie: a small piece of data a website stores in your browser so it can recognise you on later requests.
  • Credential version / password epoch: a counter that increases whenever the password changes, used to tell whether something was created under an older password.
  • CVE: a public catalogue number for a known vulnerability.
  • Full session: a real, completed logged-in state, as opposed to a pending one.
  • Hosted service: software run by a provider on their own servers, which you use over the internet and cannot patch yourself.
  • Intermediate state: a stage in the middle of a multi-step process, not the finished result.
  • Logic flaw: a bug in the rules a program follows, rather than in its code crashing.
  • MFA version: a counter that increases whenever the 2FA configuration changes.
  • Pending login: a temporary state where the password has been checked but the second factor has not yet been supplied.
  • Persistence: an attacker's ability to stay in an account after the victim thinks they have been removed.
  • Positive result: in testing, evidence that the bug is present.
  • Rolling timer: an expiry that restarts whenever the user does something, instead of running down once.
  • Session: the state of being logged in, represented by a cookie or token the server recognises.
  • State machine: a system that moves through a fixed set of stages.
  • Terminating a session: cancelling a logged-in state so the cookie or token no longer works.
  • Timeout / expiry: a deadline after which something stops being valid.
  • Token: a piece of data, similar to a cookie, that proves your identity to a server on later requests.
  • Vulnerability: a weakness in a system that an attacker could use.

Similar reports

View all

Same bug class and techniques, clearest first.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.