How-To Guide

How to Implement DPoP Sender-Constrained Tokens

Bind access tokens to a client-held key with DPoP so a stolen bearer token cannot be replayed by an attacker.

On this page

  1. Introduction
  2. The Bearer Token Problem
  3. Keys and the DPoP Proof
  4. Binding the Token to the Key at the Authorization Server
  5. Verifying the Proof at the Resource Server
  6. Nonce Challenges
  7. Practical Trade-offs
  8. Common Pitfalls and Conclusion

Introduction

A bearer token is like cash: whoever holds it can spend it. If an access token leaks through a log, a proxy or a compromised client, the attacker can use it from anywhere until it expires. DPoP (Demonstrating Proof-of-Possession, RFC 9449) changes that by binding the token to a key the legitimate client holds. The client generates a key pair, sends a signed proof with each request, and the resource server verifies the proof matches the key the token is bound to. A stolen token is then useless without the private key.

The Bearer Token Problem

A conventional access token carries no proof of who is presenting it. Any party in possession can replay it, which is exactly why token leakage is so damaging: a token logged in plaintext or intercepted once is a working credential until it expires. Sender-constraining removes the replay window by requiring the presenter to prove possession of a key.

DPoP is one form of sender constraining, alongside mTLS-bound tokens. It is attractive because it needs no client certificate infrastructure: the client generates an ephemeral key pair and proves possession with a signature per request. The public key is embedded in the proof and the token’s confirmation claim binds the token to it.

# bearer token: replay from anywhere
attacker steals token  ->  sends it  ->  accepted

# DPoP: token is bound to a key
attacker steals token  ->  has no private key
                       ->  cannot produce a valid proof
                       ->  rejected at the resource server

Keys and the DPoP Proof

The client generates a key pair and keeps the private key. For each request to the resource server, it creates a DPoP proof: a JWT signed with that private key, carrying the HTTP method and URL in the htm and htu claims, a unique jti, the issue time iat, and the public key in the jwk header. The proof travels in the DPoP header alongside the access token.

The proof is per-request: a new one is created for each call, with a fresh jti and current iat, so a captured proof cannot be replayed either. The htu claim must match the URL exactly after normalisation, which fixes the proof to that endpoint, and the htm must match the HTTP method, so a proof for a GET cannot authorise a POST.

import { SignJWT, exportJWK, generateKeyPair } from 'jose';

const { privateKey, publicKey } = await generateKeyPair('ES256');
const jwk = await exportJWK(publicKey);

export async function dpopProof(method: string, url: string): Promise<string> {
  return new SignJWT({ htm: method, htu: url, jti: crypto.randomUUID() })
    .setProtectedHeader({ alg: 'ES256', typ: 'dpop+jwt', jwk }) // public key in header
    .setIssuedAt()
    .sign(privateKey);                                           // per-request signature
}

// Authorization: DPoP <access_token>
// DPoP: <proof>

Binding the Token to the Key at the Authorization Server

During the token request, the client sends a DPoP proof, and the authorization server returns a token whose confirmation claim (cnf) carries the JWK thumbprint of the client’s public key. That thumbprint is the binding: the token is only valid when presented with a proof whose key hashes to the same thumbprint.

The token type becomes DPoP rather than Bearer in the response, and the token itself is not a bearer credential any more. Some servers also support refresh token binding, so a stolen refresh token cannot be used to mint new access tokens without the key. Bind both, or the refresh path becomes the weak link.

// Access token issued with a DPoP binding (cnf.jkt = JWK thumbprint)
{
  "iss": "https://auth.example.com",
  "sub": "user_123",
  "aud": "https://api.example.com",
  "exp": 1698249740,
  "cnf": { "jkt": "0ZcOCORZNYy-DWpqq30jZyJGHTN0d2HglBV3uiguA4I" },
  "token_type": "DPoP"
}

Verifying the Proof at the Resource Server

The resource server extracts the token, reads the jkt from its cnf claim, and verifies the DPoP proof: the signature against the jwk in the proof header, the htm and htu against the actual request, the iat within a small window, and the jti unseen before (to block replay). It then checks that the thumbprint of the proof’s public key equals the token’s jkt. If any check fails, the request is rejected.

The jti replay check needs shared state or a short acceptance window. A cache of seen jti values, keyed with a TTL equal to the allowed clock skew plus the token lifetime, prevents a captured proof from being reused within the window. Without it, a proof can be replayed by anyone who intercepts it.

export async function verifyDpop(token: string, proof: string, req: Request) {
  const { payload, header } = await jwtVerify(proof, async () => await importJwk(header.jwk));
  if (header.typ !== 'dpop+jwt') throw new Error('bad_typ');
  if (header.jwk?.kty !== 'EC') throw new Error('bad_key_type');
  if (payload.htm !== req.method) throw new Error('method_mismatch');
  if (normalise(payload.htu) !== normalise(req.url)) throw new Error('url_mismatch');
  if (Date.now() / 1000 - payload.iat > 300) throw new Error('proof_expired');
  if (await seenJti(payload.jti)) throw new Error('replay');         // shared cache
  const tokenJkt = decodeTokenCnf(token).jkt;
  if (thumbprint(header.jwk) !== tokenJkt) throw new Error('binding_mismatch');
  return true;
}

Nonce Challenges

A resource server may require the client to include a server-provided nonce in the proof, returned via a DPoP-Nonce header. The client resends the request with a proof that includes the nonce. This raises the bar further: a captured proof cannot be replayed even to a server that would otherwise accept it, because the nonce changes.

Handle the nonce handshake gracefully. On receiving a 401 with an error of use_dpop_nonce and a DPoP-Nonce header, the client should retry once with a proof that includes the nonce. Servers should rotate the nonce periodically and accept a small set of recent ones to tolerate in-flight requests during rotation.

# nonce handshake
client -> request without nonce
server -> 401 WWW-Authenticate: DPoP error="use_dpop_nonce", DPoP-Nonce: "abc123"
client -> request with proof carrying nonce "abc123"
server -> 200
# purpose: a captured proof is not enough; the nonce must be fresh

Practical Trade-offs

DPoP protects against token replay but does not protect against a fully compromised client that has both the token and the private key. Its value is that a token leaked through a channel other than the client, such as a log or a proxy, is not directly usable. Combine it with short token lifetimes and secure storage for a real reduction in risk.

There is implementation cost: every client must sign per request, and every resource server must verify, which adds latency and a dependency on the proof format. Adopt DPoP where token leakage is a realistic risk, such as public clients and high-value APIs, and weigh the complexity against the threat for internal services behind a trusted network.

# DPoP helps when the leak channel is not the client
[+] token logged / proxied / cached  -> useless without the key
[-] client fully compromised          -> attacker has the key too
# pair with: short lifetimes, per-request proofs, jti/nonce replay checks

Common Pitfalls and Conclusion

Do not verify the signature without checking htm, htu, iat and jti; an older proof for a different request is a replay. Do not compare the URL loosely, or path confusion breaks the binding. Do not skip the thumbprint comparison, which is the actual binding between token and key. Do not forget to protect the refresh token too. And do not assume DPoP removes the need for short token lifetimes.

DPoP turns a bearer token into one that only its rightful holder can use, by binding it to a key and requiring a signed per-request proof. Issue tokens with a cnf thumbprint, source proofs with htm, htu, jti and iat, verify all of them against the token’s binding, and add nonce challenges for stronger replay protection. The result is that a stolen token is no longer a working credential.

Sources: RFC 9449: OAuth 2.0 Demonstrating Proof of Possession, RFC 7638: JWK Thumbprint, RFC 6750: Bearer Token Usage.

FAQ

Does DPoP protect against a compromised client?
No. If the attacker has both the token and the client's private key, the proof verifies. DPoP protects against token leakage through channels that do not include the key, such as logs, caches or a proxy, which is the common case.
Why check the jti at the resource server?
Because a captured proof could otherwise be replayed by anyone who intercepts it. Tracking seen jti values for a short window (token lifetime plus clock skew) blocks that replay.

Related Examples