The API That Returned More Than the Profile — Bug Hunt
Modelled on the Google+ API bug (disclosed October 2018): an endpoint meant to return a user's public profile fields also returned fields the user had…
- Language: JavaScript
- Layer: Backend
- Difficulty: Medium
- Concepts: Security, API Design
- Modelled on: Google+ · 2018
- Visible tests: public fields are returned; a non-public field is omitted
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High (privacy))
- Ticket: BUG-GPLUS
- Reported by: security
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- a non-public field is omitted — asking for a field is not permission to receive it: expected {"name":"Kai"} but got {"name":"Kai","email":"k@example.com"}
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 the Google+ API bug (disclosed October 2018): an endpoint meant to return a user's public profile fields also returned fields the user had shared only with friends. Around 500,000 accounts were affected, and Google shut the consumer product down.
api.js serialises the whole record and lets the caller pick fields.
Fix publicProfile so it emits only the fields declared public, whatever the caller asks for.
Bug report
BUG-GPLUS · Priority: High (privacy) · Reported by: security
publicProfile(user, requestedFields) must return an object containing only the requested fields that are ALSO in user.publicFields — anything else is omitted silently. The result's keys must be in the order given by requestedFields.
Observed: requesting "email" on an account that shares it only with friends returns the email anyway.
Logs
[api] fields=[name,email] publicFields=[name] -> returned email
[api] 496,951 profiles affectedThe code as shipped
src/api/api.js (editable)
// Returns the caller-requested subset of a profile.
exports.publicProfile = function (user, requestedFields) {
var out = {};
for (var i = 0; i < requestedFields.length; i++) {
var f = requestedFields[i];
if (user.data.hasOwnProperty(f)) out[f] = user.data[f];
}
return out;
};
Read-only context: src/api/MODEL.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.