The Key That Joined the Wrong Repository — Bug Hunt
Modelled on GitHub, March 2012: Egor Homakov showed that a Rails mass assignment weakness let him submit an extra attribute in a public-key update form and…
- Language: JavaScript
- Layer: Backend
- Difficulty: Easy
- Concepts: Security, Validation
- Modelled on: GitHub · 2012
- Visible tests: the owner can rename a key; ownerId in the request is ignored
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-1 (priority: Critical)
- Ticket: BUG-MASSASSIGN
- Reported by: a user, publicly
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- ownerId in the request is ignored — a key's owner is not a form field: expected "egor" but got "rails"
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 request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- 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 GitHub, March 2012: Egor Homakov showed that a Rails mass assignment weakness let him submit an extra attribute in a public-key update form and attach his SSH key to the Rails organisation, then pushed a commit to the rails/rails repository to prove it. GitHub patched the endpoint the same day, and the incident pushed Rails towards strong parameters.
This project is a reconstruction. update.js edits an SSH key record by copying every submitted field onto it — including the field that says who owns it.
Fix updateKey so only the fields a user may edit are applied.
Bug report
BUG-MASSASSIGN · Priority: Critical · Reported by: a user, publicly
updateKey(store, currentUser, keyId, params):
- returns null (and changes nothing) when the key does not exist or is not owned by currentUser
- otherwise applies ONLY params.title and params.key when present — every other submitted field (ownerId, id, anything unknown) is ignored and never added to the record — and returns the record
Observed: a request carrying ownerId moved a key to another account.
Logs
[keys] PUT /keys/1 params={"title":"laptop","ownerId":"rails"} by egor
[keys] key 1 owner egor -> railsThe code as shipped
src/keys/update.js (editable)
// PUT /keys/:id — edit an SSH key the caller owns.
exports.updateKey = function (store, currentUser, keyId, params) {
var record = store.find(keyId);
if (!record || record.ownerId !== currentUser) return null;
Object.keys(params).forEach(function (field) {
record[field] = params[field];
});
return record;
};
Read-only context: src/keys/store.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.