Sender-constrained tokens: DPoP and certificate binding for API access
A bearer token works for whoever holds it. If it leaks through a log file, a compromised proxy or a malicious browser extension, an attacker can use it until it expires. Sender-constrained tokens add a second factor at the protocol level: the token is only valid together with proof of a private key that never leaves the legitimate client.
Tämä sisältö on toistaiseksi saatavilla vain englanniksi.
The problem with bearer tokens
OAuth 2.0 access tokens are, by default, bearer tokens: RFC 6750 states that any party in possession of the token can use it. This makes integration simple and is acceptable for many APIs, but it means the token itself is the only secret. Tokens end up in places their designers did not intend – debug logs, error reports, browser storage, intermediary caches – and every copy is a working credential.
Short lifetimes reduce the window, and refresh-token rotation limits long-term abuse. For APIs that move money, change ownership or expose sensitive personal data, however, a stolen token that works for even five minutes is often too much. The goal of sender-constraining is that a stolen token alone is useless.
Certificate-bound tokens (RFC 8705)
With mutual-TLS client authentication, the client presents an X.509 certificate during the TLS handshake with the authorisation server. The server issues an access token containing a confirmation claim – the SHA-256 thumbprint of that certificate, in cnf.x5t#S256. The resource server, which also terminates mutual TLS, compares the thumbprint of the certificate presented on the API connection with the one in the token and rejects the request if they differ.
This is a strong mechanism for server-to-server integrations, where clients can hold certificates and private keys securely. It requires mTLS end to end, which can be awkward behind TLS-terminating load balancers: the edge must pass the verified client certificate, or its thumbprint, to the resource server in a header that clients cannot forge.
DPoP (RFC 9449)
Demonstrating Proof of Possession works at the application layer. The client generates a key pair and, with every request, sends a DPoP header containing a short JWT signed with the private key. The proof includes the public key, the HTTP method and URL, a unique identifier and a timestamp; for resource requests it also contains a hash of the access token. The authorisation server binds the issued token to the public key’s thumbprint, and the resource server checks that each request carries a fresh, valid proof made with the matching key.
Because DPoP does not depend on TLS client certificates, it works for browser-based and mobile clients and through ordinary load balancers. Servers can additionally require a server-provided nonce in proofs to limit pre-generated proofs, and must reject reused proof identifiers within the acceptance window.
What the Security BCP recommends
RFC 9700, published in January 2025 as the OAuth 2.0 Security Best Current Practice, consolidates lessons learned since the original framework. Among its recommendations: do not use the implicit grant or the resource owner password credentials grant; use PKCE for authorisation code flows; validate redirect URIs by exact matching; restrict token privileges to the audience and scopes actually needed; and use sender-constrained access tokens, with mTLS or DPoP as the mechanisms it names.
For new high-value APIs, these recommendations are a sensible baseline. For existing APIs, they work as a migration checklist: each item removes a class of attack observed in practice.
Implementation at the gateway
Gateways are a natural place to verify sender constraints consistently. For DPoP, the gateway validates the proof signature, the method and URL, the timestamp window, the access-token hash and the binding between the token’s cnf.jkt and the proof key, and keeps a short-lived cache of seen proof identifiers to reject replays. For certificate binding, the gateway verifies the client certificate at the TLS layer and compares its thumbprint with the token.
Both checks are cheap in CPU terms, but the replay cache must be shared across gateway replicas or partitioned so that the same client always reaches the same instance. Budget its latency like any other hot-path dependency.
Limits of the approach
Sender-constraining defeats replay of leaked tokens. It does not help if the attacker controls the client itself, because the attacker can then use the private key directly. Keys should therefore be non-exportable where the platform allows – in a hardware-backed keystore on mobile devices, in a secure enclave, or in an HSM for servers. Pair sender-constrained tokens with short lifetimes, narrow scopes and anomaly detection on token use.
Token hygiene that still matters
Sender-constraining is one layer in a set of controls that work together. Access tokens should be short-lived – minutes rather than hours for high-value APIs – and carry an aud claim limited to the resource server that will accept them, so a token issued for one API cannot be replayed against another. Scopes should describe concrete capabilities, not broad roles, and resource servers should check them on every route.
JSON Web Token handling has its own well-known pitfalls, collected in RFC 8725: accept only the signing algorithms you expect, never allow none, validate issuer and audience, and fetch keys only from the configured issuer. Structured access tokens can follow the JWT profile in RFC 9068, which standardises the claims resource servers rely on.
Refresh tokens deserve particular care because they live longest. For public clients, rotate them on every use and detect reuse: if an old refresh token is presented again, revoke the whole token family, because one of the two parties presenting it is an attacker. For confidential clients, bind refresh tokens to client authentication or to the DPoP key.
Finally, keep tokens out of places they do not belong. Strip Authorization and DPoP headers from logs at the gateway, never put tokens in URLs, and make error-reporting tools redact them by default.
Esimerkki: A partner API moving from bearer to DPoP
A B2B API issued one-hour bearer tokens to partner backends and mobile apps. After a partner accidentally logged tokens to a third-party monitoring service, the provider introduced DPoP for all clients. The authorisation server began binding tokens to the client’s key thumbprint; the gateway verified proofs and kept a five-minute replay cache in a zone-local store. Server partners with existing client certificates were offered RFC 8705 binding instead. Bearer tokens remained accepted for six months on a deprecation path with warnings in response headers, then were switched off. A replayed token from a log file now fails with 401 and an error indicating an invalid proof.
Yleiset sudenkuopat
- Accepting DPoP proofs without checking the method, URL or timestamp.
- No replay cache for proof identifiers, or a cache that is local to one gateway replica.
- Terminating mTLS at a load balancer and passing the certificate in a header clients can set.
- Storing the DPoP private key in a place scripts can export.
- Treating sender-constraining as a replacement for short lifetimes and narrow scopes.
Kysymyksiä ja vastauksia
DPoP or mTLS-bound tokens?
mTLS binding suits server-to-server integrations that already manage certificates. DPoP suits browsers, mobile apps and environments where TLS terminates before the application.
Does DPoP replace PKCE?
No. PKCE protects the authorisation code exchange; DPoP protects the use of access and refresh tokens. Use both.
What about refresh tokens?
They can be bound in the same way. For public clients, binding refresh tokens to a DPoP key is one of the main benefits, because refresh tokens live much longer than access tokens.
Tarkistuslista
- Classify APIs by the impact of a leaked token.
- Remove implicit and password grants; require PKCE.
- Choose mTLS binding or DPoP per client type.
- Verify proofs or certificate thumbprints at the gateway.
- Share the replay cache across replicas.
- Keep private keys non-exportable where possible.
- Deprecate bearer tokens on high-value routes with a clear timeline.
Ensisijaiset lähteet
- RFC 6749 – The OAuth 2.0 Authorization Framework
- RFC 6750 – OAuth 2.0 Bearer Token Usage
- RFC 8705 – OAuth 2.0 Mutual-TLS Client Authentication and Certificate-Bound Access Tokens
- RFC 9449 – OAuth 2.0 Demonstrating Proof of Possession (DPoP)
- RFC 9700 – Best Current Practice for OAuth 2.0 Security
- RFC 8725 – JSON Web Token Best Current Practices