Readable Passwords at Rest — JavaScript Bug Hunt
Modelled on Facebook's 2019 disclosure: hundreds of millions of user passwords had been stored in readable form in internal systems, searchable by thousands…
- Language: JavaScript
- Layer: Database
- Difficulty: Medium
- Concepts: Security, Hashing
- Modelled on: Facebook · 2019
- Visible tests: the right password verifies; the stored record holds no readable password
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-1 (priority: Critical)
- Ticket: BUG-FB2019
- Reported by: security
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- the stored record holds no readable password — only a salt and a hash may be stored: expected ["hash","salt"] but got ["password"]
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the data through the query or the repository code; compare the rows it returns with the rows the report expects.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Modelled on Facebook's 2019 disclosure: hundreds of millions of user passwords had been stored in readable form in internal systems, searchable by thousands of employees. The passwords had never been hashed on the path that wrote them.
accounts.js stores whatever it is handed and compares it directly.
Fix createAccount and verify so passwords are stored only as salted hashes.
Bug report
BUG-FB2019 · Priority: Critical · Reported by: security
createAccount(store, username, password) must write a record shaped { salt, hash } — with no field anywhere holding the password itself. verify(store, username, password) must return true only for the right password.
Observed: the stored record contains a password field in plain text, and verify compares strings directly.
Logs
[store] record kai = {"password":"hunter2"}
[audit] 2000 internal accounts could read the users tableThe code as shipped
src/accounts/accounts.js (editable)
var crypto = require("./crypto");
exports.createAccount = function (store, username, password) {
store[username] = { password: password };
return true;
};
exports.verify = function (store, username, password) {
var record = store[username];
if (!record) return false;
return record.password === password;
};
Read-only context: src/accounts/crypto.js.
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.