# Stolen Token Gap

`demo/script.md`, beat 6 ("Stolen token is useless").

**Resolved 2026-10-02.** `poc-code/demo/replay-no-key.sh` + `replay-no-key.mjs` now exist and
are live-verified end to end: a real mandate was minted against a real running platform stub
and PDS, and the script returned exactly `403 pop_key_mismatch` for a stolen token replayed
with a forged DPoP proof. The rest of this note is kept as the design record of what the
script had to prove — still accurate, just now also built.

A more visual companion, [`stolen-token-gap.html`](stolen-token-gap.html), sits next to this
file — same content plus the diagram rendered with the checkpoint pipeline visualized.
Self-contained (no external libraries), open it directly in a browser.

## What beat 6 needs to show

An attacker who copies the `AGENT_DELEGATION_TOKEN` (the JWT) but does **not** have the
agent's private key still cannot call the PDS. The PDS's `/mcp/**` filter checks this via
Proof-of-Possession (DPoP) — see `contracts.md` §2.

## The three attempts, side by side

| Attempt | DPoP header present? (step 1) | Proof signature valid? (step 7) | Key thumbprint matches `cnf.jwk`? (step 8) | Tool allowed? (step 19) | Result |
|---|---|---|---|---|---|
| Real Outil Local, real agent key | yes | yes | yes | yes | `200` — balance returned |
| Stolen token, **no** `DPoP` header at all | **no** | — | — | — | `401 missing_dpop` |
| Stolen token + **forged** `DPoP` proof, signed with the attacker's **own** throwaway key | yes | yes | **no** | — | `403 pop_key_mismatch` |

## Why the third row is the one that matters

Sending the stolen token with **no** `DPoP` header at all only proves the PDS's *first*
check (step 1). That's a weak demo — it looks like "we forgot a header," not "the crypto
stopped an attacker."

The real point of beat 6 needs the attacker to try harder: build a **syntactically valid**
DPoP proof, correctly signed, but with their own key instead of the real agent's. That
proof passes signature verification (step 7) — it's a valid signature, just from the
wrong key — and only fails at step 8, the thumbprint match against the token's sealed
`cnf.jwk`. That's the check doing the real work, and it's the one worth putting on stage.

## What the script needs to do

```
1. generate a throwaway Ed25519 keypair (jose)
2. build a DPoP proof JWT, signed with THAT key:
     header:  { typ: "dpop+jwt", alg: "EdDSA", jwk: <throwaway pubkey> }
     payload: { htm: "POST", htu: "<canonical mcp uri>",
                iat, jti, bsha: sha256(body) }
3. POST to /mcp with:
     Authorization: DPoP <stolen AGENT_DELEGATION_TOKEN>
     DPoP: <the forged proof from step 2>
4. expect back: 403 pop_key_mismatch
```

Every field above is already pinned in `contracts.md` §2 — nothing to design, just to
write (the stub already depends on `jose`, so no new library is needed).

---
Written 2026-09-26. Resolved 2026-10-02 — see `poc-code/demo/replay-no-key.sh`.
