The API That Returned More Than the Profile

Medium

· Backend

Incident

SEV-2

BUG-GPLUS

Priority: High (privacy) · reported by security

Time to fix: 20 min

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

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. 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.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

Google+ · 2018

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.

Code map

// 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;
};

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

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

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. 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.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. 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 affected

The 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.