mTLS client authentication for OAuth (RFC 8705)
Bearer tokens have a design property that is also their worst weakness: whoever holds one can use one. The token does not care who is presenting it. So when an access token leaks — through a logging mistake, a compromised proxy, an SSRF that pulls it out of a metadata endpoint — the attacker replays it and is indistinguishable from the legitimate client. Every control you built around issuing that token is bypassed, because the token's only requirement is possession.
Mutual TLS client authentication, specified in RFC 8705, attacks this at two levels. It authenticates the OAuth client with a certificate instead of a secret, and — the part that matters most — it can bind the issued access token to that certificate, producing a certificate-bound token that is useless to anyone who cannot complete a TLS handshake with the matching private key. A stolen bound token is just bytes.
Two mechanisms in one spec
RFC 8705 defines two capabilities that are often conflated. They are independent and you can use the client authentication without the token binding, though the binding is where most of the value lives.
mTLS client authentication
During the TLS handshake with the token endpoint, the client presents a client certificate. The authorization server authenticates the client by that certificate rather than a client_secret or a signed assertion. Two profiles exist:
- PKI-based: the certificate is validated against a trusted CA, and the client is identified by a registered subject DN. Rotation means issuing a new cert from the same CA.
- Self-signed: the client registers the certificate (or its JWKS) directly and the server matches by thumbprint. No CA infrastructure required.
Certificate-bound access tokens
This is the headline feature. When the token is issued, the server records a SHA-256 thumbprint of the client's certificate inside the token, under the confirmation (cnf) claim with the key x5t#S256.
{
"iss": "https://auth.example.com",
"sub": "svc-payments",
"aud": "https://billing.example.com",
"scope": "transfers:write",
"cnf": {
"x5t#S256": "bwcK0esc3ACC3DB2Y5_lESsXE8o9ltc05O89jdN-dg2"
}
}Now the resource server enforces a second check on every request: the client must present the same certificate over mTLS, and its thumbprint must equal the cnf value in the token. Possession of the token is no longer sufficient — the client must also prove possession of the private key behind the certificate. That is what kills replay.
How the resource server enforces it
The resource server terminates (or receives a verified pass-through of) the client's mTLS connection, computes the presented certificate's thumbprint, and compares it to the token's cnf.x5t#S256.
import { createHash } from 'node:crypto';
function certThumbprint(derCert: Buffer): string {
// base64url of SHA-256 over the DER-encoded certificate
return createHash('sha256').update(derCert).digest('base64url');
}
function enforceBinding(token: DecodedToken, peerCertDer: Buffer) {
const expected = token.cnf?.['x5t#S256'];
if (!expected) throw new Error('token is not certificate-bound');
const actual = certThumbprint(peerCertDer);
if (actual !== expected) {
throw new Error('certificate thumbprint mismatch — possible token replay');
}
}The hard part: terminating mTLS in modern infrastructure
mTLS is operationally heavier than a signed assertion, and the weight is almost entirely about where TLS terminates. In a real deployment, TLS rarely terminates at your application process — it terminates at a load balancer, an ingress controller, or a service mesh sidecar.
That means the certificate your application needs to thumbprint is seen by the terminating layer, not by your code. You have to forward it. The common pattern is for the terminator to validate the client cert and pass it to the backend in a header.
# The ingress forwards the verified client leaf certificate.
# Your app trusts this header ONLY because the ingress is the sole ingress
# path and strips any client-supplied copy of it.
X-Client-Cert: -----BEGIN%20CERTIFICATE-----MIID...This introduces a trust boundary you must get exactly right: the application trusts the forwarded certificate header only if the terminating proxy is guaranteed to have validated the mTLS handshake and to strip any client-supplied copy of that header. If an attacker can reach the backend directly, or spoof the header, the binding is worthless. This is the single most important thing to review in an mTLS deployment.
mTLS versus DPoP versus private_key_jwt
All three move you off replayable bearer tokens, but they fit different infrastructures:
- mTLS (RFC 8705) binds the token at the TLS layer. It is a natural fit where you already run a service mesh or PKI and terminate mTLS cleanly. The binding is strong and the proof happens as a side effect of the connection.
- DPoP binds the token at the application layer with a per-request signed proof header. It works over ordinary TLS and is better suited to browser and mobile clients that cannot present a client certificate.
- private_key_jwt authenticates the client but does not, by itself, bind the access token to the key. It solves the shared-secret problem, not the bearer-replay problem.
Where it fits
Certificate-bound tokens turn a leaked access token from a catastrophe into a non-event: without the private key, the token cannot be used, so the usual playbook of "the token ended up in a log and someone replayed it" simply stops working. That is a large reduction in blast radius for a service-to-service edge handling sensitive operations.
The cost is real — you are taking on certificate lifecycle management and a trust boundary at your TLS terminator — so adopt it where the stakes justify it rather than everywhere. And because enabling certificate binding means your authorization server has to stamp the cnf claim and your resource servers have to enforce it in lockstep, this is far easier to run on auth infrastructure you own end to end, where both halves of the binding are yours to configure and verify together.
Run it yourself
Bastionary is free, open-source software. Follow the quick start to have it running on your own server, or browse the releases on Git.