Too Young by One Birthday — JavaScript Bug Hunt
Modelled on Twitter, 2016: after Twitter began showing balloons on users' birthdays, a prank spread urging people to change their birth year to 2007.
- Language: JavaScript
- Layer: Frontend
- Difficulty: Medium
- Concepts: Validation, Dates
- Modelled on: Twitter · 2016
- Visible tests: age after this year's birthday; age before this year's birthday; a birthday that locks the account asks first
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High)
- Ticket: BUG-BDAY-LOCK
- Reported by: account support
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- age before this year's birthday — expected 25 but got 26
- a birthday that locks the account asks first — expected {"action":"confirm","age":9,"message":"Saving this birthday will lock your account: you must be 13 or older to use this service."} but got {"action":"save","age":9,"message":""}
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 value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
- 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 Twitter, 2016: after Twitter began showing balloons on users' birthdays, a prank spread urging people to change their birth year to 2007. Twitter requires users to be at least 13, so accounts whose new birthday made them appear younger than that were locked, and their owners had to go through support to get back in.
This reconstruction is the logic behind the birthday field in the settings form. It computes ages wrongly around the birthday itself, and it saves a birthday that will lock the account without asking first.
Fix birthday.js.
Bug report
BUG-BDAY-LOCK · Priority: High · Reported by: account support
Dates are { y, m, d } with m in 1..12. ageOn(birth, today): whole years completed — today.y - birth.y, minus one if today's (month, day) is before the birth (month, day). A 29 February birthday is not yet reached on 28 February of a non-leap year and is reached on 1 March.
reviewChange(proposed, today) returns { action, age, message } (in that order):
- age < 0 (a birthday in the future): { action: "reject", age, message: "Birthday is in the future" }
- age < policy.MIN_AGE: { action: "confirm", age, message: policy.LOCK_WARNING } — the form must ask before saving a birthday that locks the account
- otherwise: { action: "save", age, message: "" }
Observed: people born later in the year are credited a year early, and a birth year of 2007 is saved straight away and the account locked.
Logs
[settings] birthday saved 2007-01-01 age=9
[accounts] locked U-5521: under minimum ageThe code as shipped
src/profile/birthday.js (editable)
var policy = require("./policy");
// Age in whole years on `today`. Dates are { y, m, d } with m in 1..12.
exports.ageOn = function (birth, today) {
return today.y - birth.y;
};
// Decides what the settings form does when the user saves a new birthday.
exports.reviewChange = function (proposed, today) {
var age = exports.ageOn(proposed, today);
if (age < 0) return { action: "reject", age: age, message: "Birthday is in the future" };
return { action: "save", age: age, message: "" };
};
Read-only context: src/profile/policy.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.