Any Email You Asked For

Medium

· Backend

Incident

SEV-1

BUG-SIWA-EMAIL

Priority: Critical · reported by security

Time to fix: 20 min

Failing checks on the shipped build

  • an address the account does not own is refused

    no token for another person's email: expected an error to be thrown

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

Sign in with Apple · 2020

Modelled on the Sign in with Apple vulnerability reported by Bhavuk Jain in 2020. During sign-in, the client could ask Apple's server for an identity token for a given email address, and the server issued a validly signed token for whatever email was requested without checking that it belonged to the signed-in Apple ID. Third-party apps that trusted the token's email could have been signed in to the wrong account. Apple fixed the check on its servers and paid a $100,000 bounty.

This reconstruction's token endpoint takes the email from the client's request when one is present.

Fix issueToken so the token's email always belongs to the authenticated account.

Code map

var signer = require("./signer");

// Issues the identity token handed back to a third-party app after the user
// signs in. session.account = { id, email, relayEmail }.
exports.issueToken = function (session, request) {
  var account = session.account;
  var email = request.email || account.email;
  return signer.sign({ sub: account.id, aud: request.clientId, email: email });
};

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.

Any Email You Asked For — JavaScript Bug Hunt

Modelled on the Sign in with Apple vulnerability reported by Bhavuk Jain in 2020.

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Security, Auth
  • Modelled on: Sign in with Apple · 2020
  • Visible tests: with no email requested the account's address is used; an address the account does not own is refused
  • Reward: 50 XP for a complete fix

Incident

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

Failing checks on the shipped build

  • an address the account does not own is refused — no token for another person's email: expected an error to be thrown

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 Sign in with Apple vulnerability reported by Bhavuk Jain in 2020. During sign-in, the client could ask Apple's server for an identity token for a given email address, and the server issued a validly signed token for whatever email was requested without checking that it belonged to the signed-in Apple ID. Third-party apps that trusted the token's email could have been signed in to the wrong account. Apple fixed the check on its servers and paid a $100,000 bounty.

This reconstruction's token endpoint takes the email from the client's request when one is present.

Fix issueToken so the token's email always belongs to the authenticated account.

Bug report

BUG-SIWA-EMAIL · Priority: Critical · Reported by: security

issueToken(session, request) — session.account = { id, email, relayEmail } (relayEmail is the account's private relay address), request = { clientId, email? }:

  • no signed-in account (session or session.account missing) -> throw
  • request.email absent -> the token's email is account.email
  • request.email present -> allowed ONLY if it is account.email or account.relayEmail (the user choosing to hide their address); any other value -> throw, and no token is signed
  • returns signer.sign({ sub: account.id, aud: request.clientId, email })

Observed: a signed-in user asked for a token with someone else's address in request.email and received a valid token carrying that address.

Logs

[idp] token issued sub=001234 email=victim@example.com (account email=user@example.com)

The code as shipped

src/idp/tokens.js (editable)

var signer = require("./signer");

// Issues the identity token handed back to a third-party app after the user
// signs in. session.account = { id, email, relayEmail }.
exports.issueToken = function (session, request) {
  var account = session.account;
  var email = request.email || account.email;
  return signer.sign({ sub: account.id, aud: request.clientId, email: email });
};

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