TL;DR
- The bearer token alone is refused with proof_required, so a copied token is not enough on its own.
- The signed proof is accepted, and the same proof is refused the second time.
- A proof from another key and a forged proof fail on the key check and the signature check.
- The legacy endpoint still accepts the bearer token alone. That is the gap a stolen token would use.
- This is a generic demo built on the ideas in Request for Comments (RFC) 9449 (DPoP). The agent-specific spec is not published yet, so those parts are marked to watch.
Repeat this lab
I wrote this lab so you can run it yourself. Each step has the commands to copy and the output I got, and you can tick it as done. Your ticks stay in this browser only.
Copies a ready-made prompt for Claude Code, Cursor, Codex or any coding agent. For test environments only.
Show prompt
I want to run a hands-on lab from iamops.dev, and I would like your help to do it safely. Lab: Agent proof of possession lab: why a copied token is not enough Read the whole lab here (Markdown): https://iamops.dev/agent-proof-of-possession-lab.md What the lab needs before the first step: - Python 3, curl, jq, openssl and tr How I want you to work: 1. Read the lab from start to finish first (each step lists its own prerequisites). Then check that the prerequisites are in place and that the tool versions match what the lab expects. Tell me what is missing before you run anything. 2. Run one step at a time. Before each command, show it to me and say in a sentence what it does. 3. Ask me before anything that costs money, creates cloud resources, touches a real tenant or account, or deletes anything. Wait for my answer. 4. Use the placeholders from the lab. Never paste real secrets, tokens or production identities into a command, a file or this chat. If a value is needed, tell me where to set it myself. 5. After each step, compare the output with the expected output in the lab. If it does not match, stop and tell me what differs. Do not carry on or invent a fix without asking me. 6. At the end, report what passed, what failed and which cleanup you did. Then offer to tick the steps off for me. The lab page keeps ticks only in my browser, so if you cannot do that, list the steps I should tick. This lab is for test environments only. Do not run it against production, or against a tenant or account that holds real data or real users. You may answer in my language.
A bearer token works for whoever holds it. If an agent’s token is copied, the copy works too, unless the resource server also checks something the copy does not have. This lab binds the token to a key and makes the resource server check a signed proof on every call.
The lab uses one Python file with the standard library, plus openssl, curl and jq. The issuer binds the token to the agent’s public key. The resource server checks the token, then the proof. The proof is signed with the agent’s private key and covers the method, the path and a hash of the token.
This is a generic demo. It follows the idea of proof of possession from RFC 9449, and it is not an implementation of the agent-specific spec. That spec is not published yet, so agent-specific spec details are marked to watch and are not claimed here.
Setup#
You need Python 3, curl, jq, openssl and tr. The issuer listens on 127.0.0.1 port 4901 and the resource server on port 4902. Nothing needs an account, and nothing leaves the computer after the download.
The service is one file, pop_lab.py, and the helper functions are in agent_proof.sh.
Step 1: Download the service and make two keys#
mkdir -p pop-lab/run && cd pop-lab
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/pop_lab.py
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/agent_proof.sh
openssl ecparam -name prime256v1 -genkey -noout -out issuer.key.pem
openssl ec -in issuer.key.pem -pubout -out issuer.pub.pem 2>/dev/null
openssl ecparam -name prime256v1 -genkey -noout -out agent.key.pem
openssl ec -in agent.key.pem -pubout -out agent.pub.pem 2>/dev/null
chmod 600 issuer.key.pem agent.key.pemThe private keys stay in files that only you can read. The cleanup step deletes them.
Step 2: Start both services#
export ISSUER=http://127.0.0.1:4901 RESOURCE=http://127.0.0.1:4902
python3 -I pop_lab.py --role issuer --port 4901 --key issuer.key.pem --log run/issuer.log > run/issuer.out 2>&1 &
echo $! >> run/pids
python3 -I pop_lab.py --role resource --port 4902 --issuer-pub issuer.pub.pem --log run/resource.log > run/resource.out 2>&1 &
echo $! >> run/pids
sleep 1
cat run/issuer.out run/resource.out
Step 3: Check the health endpoints#
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$RESOURCE/healthz" | jq -c .
Step 4: Get a token bound to the agent’s key#
source ./agent_proof.sh
TOKEN=$(curl -s -X POST "$ISSUER/token" -d agent=demo-agent -d scope=calendar.read --data-urlencode "public_key=$(cat agent.pub.pem)" | jq -r .access_token)
decode_part "$(printf '%s' "$TOKEN" | cut -d. -f2)" | jq -r '"sub: \(.sub)", "scope: \(.scope)", "cnf.jkt: \(.cnf.jkt)"'
The cnf.jkt claim is the thumbprint of the agent’s public key. That is what ties the token to the key.
Step 5: A bearer token alone is refused#
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
Step 6: The agent signs the request and the call succeeds#
PROOF=$(prove agent.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
The proof covers the method, the path, a timestamp, a one-time id and a hash of the token. A proof for one request does not work for another path or token.
Step 7: The same proof cannot be used twice#
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
Step 8: A proof from another key is refused#
openssl ecparam -name prime256v1 -genkey -noout -out attacker.key.pem
openssl ec -in attacker.key.pem -pubout -out attacker.pub.pem 2>/dev/null
ATTK=$(prove attacker.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $ATTK" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
Step 9: A proof that swaps in the agent’s public key fails the signature#
FORGED=$(prove attacker.key.pem GET /v1/calendar "$TOKEN" agent.key.pem)
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $FORGED" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
The attacker can copy the public key from the header, but cannot sign with the private key. The signature check is what stops that.
Step 10: The old endpoint still takes the bearer token alone#
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/legacy/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json
This is the lesson of the lab. Any endpoint that accepts the bearer token without the proof lets a copied token work. The fix is to require the proof everywhere the token is accepted.
Step 11: Read what the resource server logged#
cat run/resource.log
Step 12: Clean up#
kill $(cat run/pids)
rm -f body.json agent.key.pem agent.pub.pem attacker.key.pem attacker.pub.pem issuer.key.pem issuer.pub.pem pop_lab.py agent_proof.sh
cd .. && rm -rf pop-lab
lsof -nP -iTCP:4901-4902 -sTCP:LISTEN || echo "no listener on 4901 or 4902"
pgrep -fl pop_lab.py || echo "no pop_lab.py process left"
What this does not cover#
- The proof format is this lab’s own, not the agent-specific spec format. agent-specific spec is to watch until its spec is published.
- The issuer and the resource server share one local trust setup and one process each. A real deployment needs key rotation, a key store and proper token lifetimes.
- The legacy endpoint is there on purpose, to show the gap.
Repeat this lab#
You need Python 3 (no extra packages), curl, jq, openssl and tr. Everything runs on your own computer on ports 4901 and 4902, with no account and no internet access after the download. Plan for about 15 minutes. This is a generic proof-of-possession demo, not the AAuth spec, which is not published yet.
Every value in angle brackets is a placeholder for your own test environment. Nothing on this page is a real identifier or secret.
Set your variables once
export ISSUER=http://127.0.0.1:4901 RESOURCE=http://127.0.0.1:4902 0 of 11 steps done
Step 1Download the service and make two keys
Goal. Create a work folder, download the service and the helper functions, and make an issuer key and an agent key that only you can read.
Prerequisites
- Python 3, curl, jq, openssl and tr
mkdir -p pop-lab/run && cd pop-lab
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/pop_lab.py
curl -s -O https://iamops-dev.github.io/lab-files/agent-proof-of-possession-lab/agent_proof.sh
openssl ecparam -name prime256v1 -genkey -noout -out issuer.key.pem
openssl ec -in issuer.key.pem -pubout -out issuer.pub.pem 2>/dev/null
openssl ecparam -name prime256v1 -genkey -noout -out agent.key.pem
openssl ec -in agent.key.pem -pubout -out agent.pub.pem 2>/dev/null
chmod 600 issuer.key.pem agent.key.pem Expected output
(no output) Step 2Start the issuer and the resource server
Goal. Start both services on 127.0.0.1. The issuer signs the tokens, and the resource server checks the token and the proof on every call.
Prerequisites
- The setup step has completed
- Ports 4901 and 4902 are free
python3 -I pop_lab.py --role issuer --port 4901 --key issuer.key.pem --log run/issuer.log > run/issuer.out 2>&1 &
echo $! >> run/pids
python3 -I pop_lab.py --role resource --port 4902 --issuer-pub issuer.pub.pem --log run/resource.log > run/resource.out 2>&1 &
echo $! >> run/pids
sleep 1
cat run/issuer.out run/resource.out Expected output
issuer listening on 127.0.0.1:4901
resource listening on 127.0.0.1:4902 Step 3Check both health endpoints
Goal. Confirm both services answer before you send any request.
Prerequisites
- The start step has completed
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$RESOURCE/healthz" | jq -c . Expected output
{"role":"issuer","ok":true}
{"role":"resource","ok":true} Step 4Get a token bound to the agent's key
Goal. The issuer returns a token for the agent. The token carries a confirmation claim, cnf.jkt, that is the thumbprint of the agent's public key.
Prerequisites
- The health step has completed
source ./agent_proof.sh
TOKEN=$(curl -s -X POST "$ISSUER/token" -d agent=demo-agent -d scope=calendar.read --data-urlencode "public_key=$(cat agent.pub.pem)" | jq -r .access_token)
decode_part "$(printf '%s' "$TOKEN" | cut -d. -f2)" | jq -r '"sub: \(.sub)", "scope: \(.scope)", "cnf.jkt: \(.cnf.jkt)"' Expected output
sub: demo-agent
scope: calendar.read
cnf.jkt: _AjEqWefsVfSdbOwV9dDsLuYAJia9ZPF9PrLfV2N37A Step 5A bearer token alone is refused
Goal. Send the token with no proof. The resource server refuses it, because a copied bearer token is not enough.
Prerequisites
- The token step has completed
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json Expected output
HTTP 401
error: proof_required
detail: this endpoint needs an Agent-Proof header signed with the key the token is bound to Step 6The agent signs the request and the call succeeds
Goal. Sign the method, the path and the token hash with the agent's key, and send the proof in a header next to the token.
Prerequisites
- The token step has completed
PROOF=$(prove agent.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json Expected output
HTTP 200
ok: true
endpoint: /v1/calendar
agent: demo-agent
scope: calendar.read
proof: checked Step 7The same proof cannot be used twice
Goal. Send the proof from the previous step a second time. Each proof carries a one-time id, and the resource server refuses the repeat.
Prerequisites
- The proof step has completed
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $PROOF" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json Expected output
HTTP 401
error: replay
detail: this proof was already used once Step 8A proof from another key is refused
Goal. Make a second key, sign a proof with it, and send it with the agent's token. The token is bound to the first key, so the call fails.
Prerequisites
- The token step has completed
openssl ecparam -name prime256v1 -genkey -noout -out attacker.key.pem
openssl ec -in attacker.key.pem -pubout -out attacker.pub.pem 2>/dev/null
ATTK=$(prove attacker.key.pem GET /v1/calendar "$TOKEN")
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $ATTK" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json Expected output
HTTP 401
error: key_mismatch
detail: the proof key is not the key this token is bound to Step 9A proof that swaps in the agent's public key fails the signature
Goal. Sign with the second key, but put the agent's public key in the header. The key matches the token, yet the signature does not verify.
Prerequisites
- The other-key step has completed
FORGED=$(prove attacker.key.pem GET /v1/calendar "$TOKEN" agent.key.pem)
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" -H "Agent-Proof: $FORGED" "$RESOURCE/v1/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json Expected output
HTTP 401
error: bad_signature
detail: the proof signature does not verify Step 10The old endpoint still takes the bearer token alone
Goal. Call the legacy endpoint with only the bearer token. It accepts it, which is the gap a stolen token would use.
Prerequisites
- The token step has completed
curl -s -o body.json -w "HTTP %{http_code}\n" -H "Authorization: Bearer $TOKEN" "$RESOURCE/v1/legacy/calendar"
jq -r 'del(.events) | to_entries[] | "\(.key): \(.value)"' body.json Expected output
HTTP 200
ok: true
endpoint: /v1/legacy/calendar
agent: demo-agent
scope: calendar.read
proof: not required Step 11Clean up
Goal. Stop both services, delete the keys and the service files, remove the work folder, and check that nothing listens on the two ports.
Prerequisites
- The earlier steps have completed
kill $(cat run/pids)
rm -f body.json agent.key.pem agent.pub.pem attacker.key.pem attacker.pub.pem issuer.key.pem issuer.pub.pem pop_lab.py agent_proof.sh
cd .. && rm -rf pop-lab
lsof -nP -iTCP:4901-4902 -sTCP:LISTEN || echo "no listener on 4901 or 4902"
pgrep -fl pop_lab.py || echo "no pop_lab.py process left" Expected output
no listener on 4901 or 4902
no pop_lab.py process left Sources#
This post as Markdown · RSS · JSON feed
New posts by email
One email a week with new posts and labs. Unsubscribe anytime.
Your address is stored with Kit, which sends the emails. Details