Facebook Reset Code Rate Limits: Lessons From a $15K Bug
Facebook's main site limited password reset code attempts, but some beta hosts serving the same recovery feature did not. An attacker could have guessed reset codes without restriction, potentially allowing unauthorised password changes on other users' accounts.
medium.com
Published on medium.com
Bug Bounty
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.
Context
Facebook's password reset flow sends a verification code to the account owner, who submits it back to prove control of the account before setting a new password. The flow only works as a security boundary if the number of verification attempts is capped. Anand Prakash reported in March 2016 that Facebook's main site enforced such a limit, but some beta hosts that served the same recovery feature did not. Facebook fixed the issue promptly and paid $15,000, according to the researcher.
This is an analytical case study of that public disclosure, not an original discovery. The disclosure deliberately omits reproduction details, and so does this article.
Setup
The disclosure does not describe accounts, roles, tools or versions. What it establishes is the precondition that matters: the same password reset verification feature was reachable through more than one host, and the hosts did not behave identically. No request, response, endpoint, parameter or header is published in the source, so none can be shown here.
Finding it
The researcher noticed an inconsistency rather than a missing control. The main Facebook site limited how many times a reset code could be submitted, while some beta hosts serving the same recovery feature did not. One entry point enforced the limit and another did not, which means the protection was only as strong as its weakest surface.
The disclosure does not explain Facebook's internal architecture, so the reason the beta hosts differed is not known. The observation itself is enough: a control that exists on one surface but not another is effectively optional.
Exploitation
The disclosure does not publish a step-by-step exploitation sequence, and this article intentionally omits reproduction details. At the level the researcher describes it, the flow is:
- Trigger a password reset for a target account so that a verification code is issued.
- Reach the verification step through a beta host that serves the same recovery feature instead of the main site.
- Submit candidate codes against that host. Because the host does not cap attempts, guessing is not stopped there, even though the main site would have stopped it.
No payloads, URLs or responses from this sequence appear in the source.
Root cause
The mistake is inconsistent enforcement: one entry point limited attempts and another did not.
Why the existing defence did not stop this is only implied: the limit lived on one surface and was not inherited by the others. The disclosure gives no code and no architectural detail, so any deeper explanation would be speculation.
Impact
The researcher reported that the gap could have allowed unauthorised password changes on other users' accounts. Any reset weakness puts the whole account at risk, because reset flows sit upstream of every other protection. The disclosure does not quantify the impact.
Severity and CVSS were not reported. The bounty was $15,000, as reported by the researcher. No CVE is stated in the disclosure. A CWE-307 mapping (improper restriction of excessive authentication attempts) is an analytical label, not something taken from the source.
Fix
Facebook fixed the issue promptly in 2016, according to the researcher; the disclosure does not describe the change. The defensive measures below are the author's own analysis, not a description of Facebook's patch.
- Make the limit a property of the reset request, stored server-side, so every frontend calling the verification service inherits it automatically.
- Update atomically and commit before raising errors. A check-then-increment race lets parallel requests slip past the cap, and on many frameworks raising inside a transaction rolls it back, silently undoing the increment. Decide inside, commit, then raise.
# Pseudocode: persist the attempt, commit, THEN raise
with db.transaction():
r = db.query(ResetRequest).filter_by(id=reset_id)\
.with_for_update().one() # row lock
if r.used or r.expired() or r.attempts >= MAX_ATTEMPTS:
r.used = True
verdict = "locked"
else:
r.attempts += 1 # failed tries persist
ok = hmac.compare_digest(r.code_hash, hash_code(submitted))
if ok:
r.used = True # consume on success
verdict = "ok" if ok else "invalid"
# committed; raising here can't roll back the counter
if verdict == "locked": raise ResetLocked()
if verdict == "invalid": raise InvalidCode()
- Expire and consume codes. Choose a lifetime that fits your risk and delivery latency, and invalidate the code on success or lockout.
- Control every host. Keep an inventory of every hostname, app version and API gateway that can reach auth endpoints, including beta, staging and legacy mobile. Route all of them through the same verification service rather than duplicating logic. Add automated tests that call each surface and assert the lockout triggers identically. Take non-production frontends off the public internet or put them behind SSO.
- Layer edge throttling by IP, device and account as a second control, never the only one.
- Monitor and notify. Alert on repeated failed verifications for an account and tell the user that a reset was attempted.
Variants to test
- Parallel submissions against the same reset request. Fire many verification attempts at once and check whether more than the cap are processed. A positive result is a counter that ends below the number of attempts made, or a success after the cap should have locked the request.
- Alternate hosts for the same flow. Enumerate beta, staging, legacy mobile and API gateway hostnames that reach the reset verification, and repeat the capped attempts against each. A positive result is any surface that accepts attempts past the limit enforced elsewhere.
- Error paths that roll back the counter. Trigger failures that raise inside the transaction and then check whether the attempt count persisted. A positive result is a counter that does not increase after a failed verification.
- Code reuse after success or lockout. Submit a valid code, then reuse it, and repeat after lockout. A positive result is a code that still verifies when it should have been consumed.
- Expiry boundaries. Submit codes just before and just after the intended lifetime. A positive result is a code accepted after it should have expired.
Key takeaways
- Controls must be enforced in shared logic and tested on every surface.
- Atomic counters and commit-before-raise prevent subtle throttle bypasses.
- Beta and legacy hosts are production from an attacker's point of view.
Research by Anand Prakash: How I could have hacked all Facebook accounts (March 2016). Facts come from that post; the analysis, code and remediation above are original suggestions.
What happened, in plain words
In 2016, a security researcher named Anand Prakash found a weakness in how Facebook handled password resets. Facebook's main website put a limit on how many times someone could try to enter the code that Facebook sends you when you forget your password. But some of Facebook's test or "beta" websites, which offered the same password reset feature, did not have that limit. Because the limit was missing on those other websites, someone could keep guessing the code there without being stopped. Facebook fixed the problem quickly and paid the researcher $15,000, according to his own account.
This article is a study of that public disclosure. It is not the author's own discovery, and the disclosure deliberately leaves out the exact steps needed to repeat the attack. This article leaves those details out too.

AI-generated illustration.
The background you need
Before the details make sense, here are a few ideas explained from scratch.
Password reset flow. When you click "Forgot password" on a website, the site cannot simply let anyone set a new password, because then anyone could take over your account. Instead it sends a short code to you, usually by email or text message, and asks you to type it back. Typing the right code proves you control the email address or phone number on the account. Only then does the site let you choose a new password. This whole sequence is the password reset flow.
Verification code. The short number the site sends you. It is meant to be hard for anyone else to know. Think of it like a combination lock with only a few digits: fine if you get one or two tries, useless if you can sit there turning the dial all day.
Rate limiting (attempt limiting). A rule that says "you may only try this a certain number of times." It is the digital version of a cash machine that swallows your card after three wrong PINs. Without it, a short code is just a matter of time to guess.
Host. A host is one server (or one website address) that answers requests. A company like Facebook runs many hosts: the main site, test sites, older mobile versions and so on. They can look the same to you in a browser but be separate machines running separate code.
Beta host. A test version of a site, used before changes go live to everyone. It often runs the same features as the real site, sometimes with older or less polished protections.
API and API gateway. An API is the doorway a program uses to talk to a service, the way a browser talks to a website. An API gateway is the front door that many programs go through. If a feature is reachable through several doorways, each doorway needs the same lock.
Server-side. Something stored and checked on the company's computers, not in your browser. A limit kept server-side applies no matter which browser or app you use. A limit kept only in the browser can be ignored by anyone who knows how.
Cookie or token. A small piece of data your browser holds to prove who you are after you log in. It is like a wristband at an event: show it and you get back in without proving your identity again.
Vulnerability class. Security problems are grouped into families. This one belongs to the family "improper restriction of excessive authentication attempts," which simply means "the system did not stop people from trying too many times." The label CWE-307 is the official catalogue number for that family. The article notes this label is an analytical mapping added by the author, not something the original disclosure stated.
The setup
The disclosure does not describe which accounts, tools or software versions were involved. What it does establish is the important precondition: the same password reset verification feature could be reached through more than one host, and those hosts did not behave the same way. No request, response, web address, parameter or header is published in the source, so none can be shown here.
How it was found
The researcher noticed an inconsistency rather than a completely missing protection. The main Facebook site limited how many times a reset code could be submitted. Some beta hosts serving the same recovery feature did not. One entrance enforced the limit and another did not, which means the protection was only as strong as its weakest surface. Picture a building with a locked front door and an unlocked side door: the lock exists, but it does not protect the building.
The disclosure does not explain Facebook's internal architecture, so why the beta hosts differed is not known. The observation itself is enough: a control that exists on one surface but not another is effectively optional.
How the attack would work
The disclosure does not publish a step-by-step exploitation sequence, and this article intentionally omits reproduction details. At the level the researcher describes it, the flow is:
- Trigger a password reset for a target account so that a verification code is issued. This is the same "Forgot password" button anyone can press; it starts the process and causes the site to send a code to the real owner.
- Reach the verification step through a beta host that serves the same recovery feature instead of the main site. The point of this step is to use the doorway that lacks the lock.
- Submit candidate codes against that host. Because the host does not cap attempts, guessing is not stopped there, even though the main site would have stopped it.
No payloads, web addresses or responses from this sequence appear in the source.
Why it worked
The mistake is inconsistent enforcement: one entrance limited attempts and another did not. In everyday terms: the rule was written on the door of one shop, not on the product itself, so a second shop selling the same product had no rule at all.
Why the existing defence did not stop this is only implied: the limit lived on one surface and was not inherited by the others. The disclosure gives no code and no architectural detail, so any deeper explanation would be speculation.
What the impact could have been
The researcher reported that the gap could have allowed unauthorised password changes on other users' accounts. Any reset weakness puts the whole account at risk, because reset flows sit upstream of every other protection. A reset weakness puts the whole account at risk.
The disclosure does not quantify the impact.
Severity and CVSS (standard scoring systems for how serious a bug is) were not reported. The bounty was $15,000, as reported by the researcher. No CVE (the public identifier given to a specific vulnerability) is stated in the disclosure. The CWE-307 mapping is an analytical label, not something taken from the source.
How to fix it
Facebook fixed the issue promptly in 2016, according to the researcher; the disclosure does not describe the change. The defensive measures below are the author's own analysis, not a description of Facebook's patch.
- Make the limit a property of the reset request, stored server-side, so every frontend calling the verification service inherits it automatically. In other words, put the rule on the product, not on the shop door.
- Update atomically and commit before raising errors. Two ideas are packed in here. "Atomically" means the count is updated in one indivisible step, so two simultaneous guesses cannot both read the old number and both slip past the cap. "Commit before raising" means the saved count is made permanent before the code reports an error; on many frameworks, raising an error inside a transaction rolls the transaction back, silently undoing the increment. Decide inside, commit, then raise.
# Pseudocode: persist the attempt, commit, THEN raise
with db.transaction():
r = db.query(ResetRequest).filter_by(id=reset_id)\
.with_for_update().one() # row lock
if r.used or r.expired() or r.attempts >= MAX_ATTEMPTS:
r.used = True
verdict = "locked"
else:
r.attempts += 1 # failed tries persist
ok = hmac.compare_digest(r.code_hash, hash_code(submitted))
if ok:
r.used = True # consume on success
verdict = "ok" if ok else "invalid"
# committed; raising here can't roll back the counter
if verdict == "locked": raise ResetLocked()
if verdict == "invalid": raise InvalidCode()
Line by line, in plain words:
with db.transaction():opens a database transaction. A transaction is a group of changes that either all happen or none happen, like a bank transfer that must debit one account and credit another together.r = db.query(ResetRequest).filter_by(id=reset_id)\looks up the record for this particular reset request, the one tied to the code being checked..with_for_update().one()fetches exactly one record and locks it for the duration of the transaction. The lock means a second request has to wait its turn, so two guesses cannot read the same attempt count at the same moment. This is the "atomic" part.if r.used or r.expired() or r.attempts >= MAX_ATTEMPTS:checks three things: has the code already been used, has it expired, or has the attempt count reached the maximum allowed.r.used = Trueandverdict = "locked"mark the request as locked and remember that decision, without raising an error yet.else:covers the case where the request is still usable.r.attempts += 1increases the attempt count by one. The comment notes that failed tries persist, meaning the count is saved even when the guess is wrong.ok = hmac.compare_digest(r.code_hash, hash_code(submitted))compares the submitted code with the stored one. The code is stored as a hash (a scrambled fingerprint) rather than in plain text, andhmac.compare_digestcompares in a way that does not leak timing information to an attacker.if ok:andr.used = Truemark the code as consumed when the guess is correct, so it cannot be reused.verdict = "ok" if ok else "invalid"records the outcome.# committed; raising here can't roll back the counteris the key comment: the transaction has now been saved, so the attempt count is permanent.if verdict == "locked": raise ResetLocked()andif verdict == "invalid": raise InvalidCode()now report the error to the caller. Because the save already happened, the error cannot undo the count.
- Expire and consume codes. Choose a lifetime that fits your risk and delivery latency, and invalidate the code on success or lockout. A code that lives forever is a code that can be guessed forever.
- Control every host. Keep an inventory of every hostname, app version and API gateway that can reach auth endpoints, including beta, staging and legacy mobile. Route all of them through the same verification service rather than duplicating logic. Add automated tests that call each surface and assert the lockout triggers identically. Take non-production frontends off the public internet or put them behind SSO (single sign-on, a login wall shared across internal tools).
- Layer edge throttling by IP, device and account as a second control, never the only one. "Edge" means the outermost layer, before requests reach your application. "IP" is the network address a request comes from. Throttling means slowing or blocking after too many requests.
- Monitor and notify. Alert on repeated failed verifications for an account and tell the user that a reset was attempted. If someone is guessing, the real owner should hear about it.
Things to test on your own systems
- Parallel submissions against the same reset request. Fire many verification attempts at once and check whether more than the cap are processed. A positive result is a counter that ends below the number of attempts made, or a success after the cap should have locked the request.
- Alternate hosts for the same flow. Enumerate beta, staging, legacy mobile and API gateway hostnames that reach the reset verification, and repeat the capped attempts against each. A positive result is any surface that accepts attempts past the limit enforced elsewhere.
- Error paths that roll back the counter. Trigger failures that raise inside the transaction and then check whether the attempt count persisted. A positive result is a counter that does not increase after a failed verification.
- Code reuse after success or lockout. Submit a valid code, then reuse it, and repeat after lockout. A positive result is a code that still verifies when it should have been consumed.
- Expiry boundaries. Submit codes just before and just after the intended lifetime. A positive result is a code accepted after it should have expired.
Key takeaways
- Controls must be enforced in shared logic and tested on every surface.
- Atomic counters and commit-before-raise prevent subtle throttle bypasses.
- Beta and legacy hosts are production from an attacker's point of view.
Research by Anand Prakash: How I could have hacked all Facebook accounts (March 2016). Facts come from that post; the analysis, code and remediation above are original suggestions.
Glossary
- API: the doorway a program uses to talk to a service, the way a browser talks to a website.
- API gateway: the front door that many programs go through to reach a service.
- Atomic update: a change that happens in one indivisible step, so two simultaneous requests cannot both slip past a check.
- Attempt limiting (rate limiting): a rule capping how many times something can be tried, such as entering a code.
- Auth endpoint: the part of a system that handles logging in, resetting passwords and similar identity checks.
- Beta host: a test version of a website, often running the same features as the live site.
- Bounty: a payment a company makes to a researcher who reports a security problem.
- Code hash: a scrambled fingerprint of a code, stored instead of the code itself.
- Commit: to make a database change permanent.
- Cookie / token: a small piece of data your browser holds to prove who you are after logging in.
- CVE: the public identifier given to a specific vulnerability.
- CVSS: a standard scoring system for how serious a vulnerability is.
- CWE-307: the catalogue label for "improper restriction of excessive authentication attempts."
- Edge throttling: slowing or blocking requests at the outermost layer, before they reach the application.
- Hash: a one-way scramble of data, used to store secrets without keeping them in plain text.
- Host: one server or website address that answers requests.
- IP address: the network address a request comes from.
- Password reset flow: the sequence where a site sends a code to prove you own an account before letting you set a new password.
- Pseudocode: code written to explain logic, not meant to run as-is.
- Rate limiting: see attempt limiting.
- Rollback: undoing a database change, often automatically when an error is raised inside a transaction.
- Row lock: a database lock on one record, so only one request can change it at a time.
- Server-side: stored and checked on the company's computers, not in your browser.
- SSO (single sign-on): one shared login wall used across internal tools.
- Transaction: a group of database changes that either all happen or none happen.
- Verification code: the short number a site sends you to prove you control an account.
- Vulnerability class: a family of security problems with similar causes.