Document 000000001, No Login Required

Medium

· Backend

Incident

SEV-1

BUG-FAF2019

Priority: Critical (IDOR) · reported by security

Time to fix: 20 min

Failing checks on the shipped build

  • another user is refused

    an id is not a capability: expected {"status":403,"doc":null} but got {"status":200,"doc":{"id":"d1","ownerId":"u1","body":"deed"}}

  • an anonymous caller is refused

    expected {"status":401,"doc":null} but got {"status":200,"doc":{"id":"d1","ownerId":"u1","body":"deed"}}

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

First American · 2019

Modelled on the First American Financial exposure (May 2019): document URLs used sequential IDs and the endpoint performed no authorization check. Changing the number in the URL walked 885 million records of mortgage paperwork, including bank statements and social security numbers.

documents.js returns any document whose id is requested.

Fix getDocument so a caller may only read documents they own.

Code map

// Fetches a document by id.
exports.getDocument = function (store, docId, session) {
  var doc = store[docId];
  return { status: 200, doc: doc };
};

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.

Document 000000001, No Login Required — JavaScript Bug Hunt

Modelled on the First American Financial exposure (May 2019): document URLs used sequential IDs and the endpoint performed no authorization check.

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Security, Authorization
  • Modelled on: First American · 2019
  • Visible tests: the owner can read their document; another user is refused; an anonymous caller is refused
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical (IDOR))
  • Ticket: BUG-FAF2019
  • Reported by: security
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • another user is refused — an id is not a capability: expected {"status":403,"doc":null} but got {"status":200,"doc":{"id":"d1","ownerId":"u1","body":"deed"}}
  • an anonymous caller is refused — expected {"status":401,"doc":null} but got {"status":200,"doc":{"id":"d1","ownerId":"u1","body":"deed"}}

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 First American Financial exposure (May 2019): document URLs used sequential IDs and the endpoint performed no authorization check. Changing the number in the URL walked 885 million records of mortgage paperwork, including bank statements and social security numbers.

documents.js returns any document whose id is requested.

Fix getDocument so a caller may only read documents they own.

Bug report

BUG-FAF2019 · Priority: Critical (IDOR) · Reported by: security

getDocument(store, docId, session) must return { status, doc }:

  • { status: 401, doc: null } when session is missing or has no userId
  • { status: 404, doc: null } when the document does not exist
  • { status: 403, doc: null } when the document's ownerId is not the caller
  • { status: 200, doc } otherwise

Observed: any id returns the document, with or without a session.

Logs

[docs] served doc 000000002 to anonymous caller
[docs] 885,000,000 documents enumerable by incrementing the id

The code as shipped

src/docs/documents.js (editable)

// Fetches a document by id.
exports.getDocument = function (store, docId, session) {
  var doc = store[docId];
  return { status: 200, doc: doc };
};

Read-only context: src/docs/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.