Student worksheet: Who can reset this account?
Your mission
The campus app lets a person who forgot a password recover their account. That is useful. But how should it distinguish the owner from someone who only knows the owner's email address?
You will observe the unsafe design, write a better requirement, connect a supplied helper, and prove the repaired flow still works. Read safety. Allow 75–90 minutes after setup.
1. Prepare your workspace (5 minutes)
Your app folder is exercises/08-insecure-design/student in the repository, or app in an exported student kit. Open it in your editor and open its terminal. All commands in this worksheet run from that folder.
node --version
node server.mjs
Node must be 22 or newer. Leave the server running and open http://127.0.0.1:3000. Stop other lessons using that address first. You are using a real server running only on your own computer, not a screenshot or simulated terminal.
Make your own copy of the submission template. Save results as you go; the next action may replace displayed feedback. Copied text or screenshots are both acceptable. Use only these fictional details:
| Item | Value |
|---|---|
| Alice's account | alice@campus.example |
| Bob's account | bob@campus.example |
| Initial password for both | Campus-demo-42! |
| New password for Alice | Recovered-demo-42! |
2. Observe the unsafe design (10 minutes)
- In 2. Verify the password, replace the prefilled password with
Campus-demo-42!, keep Alice's email selected, and click Check password. Record the successful result. The app prefills the proposed new password for later steps, so do not simply submit that default here. - Act as someone who knows Alice's address but cannot read her mailbox. Do not request a token or open the teaching mailbox. In the recovery-completion form, use Alice's email and the new password. Leave the token field empty and submit.
- Record the result. The starter allows the change even though you provided no proof of ownership.
- Check Alice's login with the new password, then the original password. Save both results: the new one works and the original one no longer works.
The fact that the form works is not the same as being safe. The design is missing a requirement about who may change a password. Hiding the form or making the browser require a nonempty token would not establish proof on the server.
The numbers beside results are HTTP status codes, short labels from the server. In this lab, 200 means the action succeeded, 401 means the password was not accepted, and 403 means recovery was rejected. Read the message too: a 200 recovery-request acknowledgement does not mean a password changed.
3. Design the missing rule (10–15 minutes)
| Term | Plain meaning |
|---|---|
| Identifier | A name used to find an account, such as an email address. It is not necessarily secret. |
| Proof of control | Evidence that the requester controls the account's recovery channel, not just that they know its address. |
| Token | A hard-to-guess temporary value sent to that channel. It is separate from the account password. |
| Account binding | Alice's token must not reset Bob's account. |
| Expiry | A token stops working after its allowed lifetime. This lab uses ten minutes. |
| Single use | Once accepted, a token must not work again. Requesting a replacement also makes the older token invalid in this lab. |
| Trust boundary | The point at which untrusted input must be checked before the server performs a protected action. |
Complete these statements before editing code:
- The valuable thing we protect is ...
- Someone who only knows Alice's email could ...
- Before changing a password, the server must ...
- If proof is missing, wrong, expired, reused or for another account, the server must ...
Write the intended sequence in your own words: request recovery, receive proof through the owner's channel, submit that proof with a new password, validate it, then change the password. A rejected attempt must leave the password unchanged.
The local teaching mailbox is visible so you can play the owner without using real email. For attacker attempts, leave it closed. For owner recovery, explicitly switch roles and open it. In a real service, exposing this mailbox to everyone would defeat the design.
4. Repair the server policy (15 minutes)
Save a copy of recovery-policy.mjs outside the app folder as your before evidence. Open the original file in your editor. You will change an import and one guard, not the HTML, helper or tests.
The starter's guard is:
if (!state.accounts.has(email)) return false;
It asks only whether the account exists. That does not prove that the requester owns it.
Use this supplied helper:
| Helper | Meaning | Call form |
|---|---|---|
consumeRecoveryToken | Checks that the token belongs to the account, is unexpired and unused; consumes a valid token. Returns true only when proof is accepted. | consumeRecoveryToken(state, email, token) |
setAccountPassword | Updates the account password after approval. This call is already present; keep it. | setAccountPassword(state, email, password) |
- Add
consumeRecoveryTokento the existing named import from./recovery-helpers.mjs, separated fromsetAccountPasswordby a comma. - Replace
state.accounts.has(email)in the guard with the helper call that verifies the token. Keepif (!and) return false;around it. - Leave the
setAccountPasswordline after the guard, so rejected proof cannot change the password. Save the file.
Your import line should now look like this; keep the function underneath it:
import { consumeRecoveryToken, setAccountPassword } from './recovery-helpers.mjs';
import makes a supplied function available; a function is a named operation. ! means “not.” return false stops this operation and reports rejection. You do not need to invent token generation or password hashing.
Explain why the check belongs before the password change and on the server, not just in the browser.
5. Restart and verify rejection (10 minutes)
Save your file, press Ctrl+C in the server terminal, run node server.mjs again and refresh the page. Both accounts now have the initial password again. Restart also clears tokens and mailbox messages.
Repeat the empty-token attempt from section 2. This time it must be rejected. Record that result, then verify Alice's original password still works and the proposed new password does not. Try not-a-real-token too; rejection must not depend only on whether a field is empty.
6. Verify owner recovery and replay protection (10–15 minutes)
- Switch to the role of Alice, the owner. This is a role-playing step, not a login or a separate “switch role” button. In 3. Switch roles: account owner, enter
alice@campus.exampleand click Request recovery message. The acknowledgement should not reveal a token or promise that an account exists. - Open the teaching mailbox, find Alice's latest token and copy the entire value without spaces. This stands in for Alice reading her private email.
- In the completion form, enter Alice's email, that token and
Recovered-demo-42!. Submit and save the successful result. - Verify login succeeds with the new password and fails with the original password. Save both results.
- Submit the same token again, proposing
Second-demo-42!. Record its rejection. Check thatRecovered-demo-42!still works. This shows the rejected replay did not change the password.
Tokens are random. Yours should not match the screenshots. If ten minutes pass, request a new one; an older token will no longer work. Do not wait for expiry just to finish the lab; the checks below advance an internal test clock.
7. Run the checks and submit (10–20 minutes)
Stop the server with Ctrl+C. From the same app folder:
node checks.mjs
These checks use fresh fictional state, not your browser session. They verify legitimate recovery and rejection of missing, incorrect, expired, cross-account, superseded and replayed tokens. The untouched starter passes five and intentionally fails seven checks. After your repair, expect 12/12 checks passed. Save the full output. Do not change tests to obtain a passing result.
Submit the completed template and your edited recovery-policy.mjs. Include your before/after observations, the requirement you wrote before coding, and one production concern not solved by the lesson. Explain why passing the normal login check alone would have missed the original design flaw.
If something goes wrong
| Symptom | Action |
|---|---|
| Node missing or older than 22 | Ask your instructor for the approved installation method. |
| Cannot find server.mjs | Open the terminal in the app folder, not the repository root or ZIP. |
| Another lesson appears or port 3000 is in use | Stop that lesson's server with Ctrl+C before starting this one. |
| Cannot reach the local app | Start the server, read any terminal error, and refresh. |
| Code change has no effect | Save, stop, restart, refresh. Refresh alone does not reload server code. |
| Token rejected after restart/reset | Expected: old tokens are invalid. Request a fresh token. |
| A new request makes the previous token fail | Expected: use the latest token for that account. |
| Owner recovery fails | Check the account, copy the full latest token, and ensure it has not been used or expired. |
| SyntaxError or helper not defined | Check the import, comma, spelling, parentheses and semicolons against section 4. |
| Some checks fail | Read their names; compare the guard and import with the helper table. Do not edit helpers/tests. |
| Need to repeat an observation | Use the lab reset control or restart. Both restore initial passwords and clear tokens. Save evidence first. |
In the wild: real-world case study
Account recovery and password reset bypasses (2019)
- Incident & Year: Instagram Password Reset Vulnerability (2019)
- Vulnerability: No CVE assigned (Disclosed via Bug Bounty Program) · CWE-640 (Weak Password Recovery Mechanism for Forgotten Password) · OWASP A06:2025 Insecure Design
- Root Cause: Instagram's mobile account recovery flow issued six-digit verification codes sent via SMS. Although per-IP rate limiting existed, the endpoint lacked global rate limiting across the token space. A security researcher demonstrated that sending 200,000 concurrent race-condition requests across rotating cloud IP addresses within the ten-minute window allowed guessing the passcode and triggering an unauthorized reset.
- Real-World Impact: The vulnerability allowed an unauthenticated attacker to take over any Instagram user account in under ten minutes without access to the victim's phone or email. Meta awarded a $30,000 bug bounty reward for the responsible disclosure prior to malicious exploitation.
- Remediation Tie-In: Exercise 08 highlights the principle of secure design: ensuring password reset mechanisms mandate strong proof of ownership using high-entropy random tokens, single-use invalidation, strict rate limiting, and safe fallback states that leave original credentials intact until verification succeeds.
- References: Laxman Muthiyah Account Takeover Writeup · OWASP Forgot Password Cheat Sheet · CWE-640 Definition