The Consumer Key That Opened Enterprise Mail

Medium

· Backend

Incident

SEV-1

BUG-S0558

Priority: Critical (token forgery) · reported by incident response

Time to fix: 20 min

Failing checks on the shipped build

  • a consumer key cannot sign an enterprise token

    key belongs to another issuer: expected untrusted-key but got ok

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

Microsoft · Storm-0558 (2023)

Modelled on Storm-0558 (disclosed July 2023): a China-based threat actor forged authentication tokens with an acquired Microsoft account (MSA) consumer signing key and used them to read enterprise email at a number of organisations, including US government agencies. Microsoft's investigation found that a token-validation flaw allowed the consumer key to be trusted for enterprise tokens.

This project is a reconstruction. TokenValidator checks the token's issuer and signature, but it looks the signing key up in the whole key ring — so a key that belongs to a different issuer is happily accepted as long as the signature verifies.

Fix validate so a token is only verified with a key that its own issuer publishes.

Code map

class TokenValidator {
    // Returns "ok" or the reason the token is refused.
    static String validate(KeyRing ring, Token t, String expectedIssuer) {
        if (!t.iss.equals(expectedIssuer)) return "wrong-issuer";
        SigningKey key = ring.find(t.kid);
        if (key == null) return "untrusted-key";
        if (!Signer.sign(key.secret, t.payload()).equals(t.sig)) return "bad-signature";
        return "ok";
    }
}

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 Consumer Key That Opened Enterprise Mail — Java Bug Hunt

Modelled on Storm-0558 (disclosed July 2023): a China-based threat actor forged authentication tokens with an acquired Microsoft account (MSA) consumer…

  • Language: Java
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Security, Auth
  • Modelled on: Microsoft · Storm-0558 (2023)
  • Visible tests: a genuine enterprise token validates; a consumer key cannot sign an enterprise token
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical (token forgery))
  • Ticket: BUG-S0558
  • Reported by: incident response
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • a consumer key cannot sign an enterprise token — key belongs to another issuer: expected untrusted-key but got ok

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 Storm-0558 (disclosed July 2023): a China-based threat actor forged authentication tokens with an acquired Microsoft account (MSA) consumer signing key and used them to read enterprise email at a number of organisations, including US government agencies. Microsoft's investigation found that a token-validation flaw allowed the consumer key to be trusted for enterprise tokens.

This project is a reconstruction. TokenValidator checks the token's issuer and signature, but it looks the signing key up in the whole key ring — so a key that belongs to a different issuer is happily accepted as long as the signature verifies.

Fix validate so a token is only verified with a key that its own issuer publishes.

Bug report

BUG-S0558 · Priority: Critical (token forgery) · Reported by: incident response

TokenValidator.validate(ring, token, expectedIssuer) returns, checking in order:

  1. "wrong-issuer" if token.iss != expectedIssuer
  2. "untrusted-key" if token.kid is not one of ring.keysFor(token.iss) — a key held in the ring for ANOTHER issuer does not count
  3. "bad-signature" if Signer.sign(key.secret, token.payload()) != token.sig
  4. "ok" otherwise

Observed: a token signed with the consumer key "msa-1" but claiming the enterprise issuer validates as "ok" at the enterprise endpoint.

Logs

[owa] token kid=msa-1 iss=https://sts.windows.net/contoso sub=ceo@contoso -> ok
[audit] mailbox access by forged enterprise token signed with consumer key

The code as shipped

src/auth/TokenValidator.java (editable)

class TokenValidator {
    // Returns "ok" or the reason the token is refused.
    static String validate(KeyRing ring, Token t, String expectedIssuer) {
        if (!t.iss.equals(expectedIssuer)) return "wrong-issuer";
        SigningKey key = ring.find(t.kid);
        if (key == null) return "untrusted-key";
        if (!Signer.sign(key.secret, t.payload()).equals(t.sig)) return "bad-signature";
        return "ok";
    }
}

Read-only context: src/auth/KeyRing.java, src/auth/Token.java.

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 Java bug hunts.