Skip to content
GatewayMarkdown

Bound tokens at the gateway

The gateway takes a token bound to a key only with a fresh proof from that key, and one bound to a certificate only over that certificate, so a copied token is useless at your APIs.

AvailableAPIRFC 9449, RFC 8705

A bearer token works for whoever holds it. A bound token works only for the client that holds its key: the realm binds it to a key (DPoP) or a client certificate (Certificate-bound tokens), and the gateway checks the binding on every request. A token copied out of an agent’s environment, a log or a proxy is refused at your APIs as it is at the realm.

Agents’ clients are held to the FAPI 2.0 profile (Security profiles) unless they name another or attest, so a non-attesting agent’s tokens are bound by default. Require binding at the gateway, and it refuses every unbound token too.

  • The gateway running in front of your API: see Run the gateway. Its image isn’t published yet: ask your Cvyūh contact for it.
  • To bind a client’s tokens in the realm, a realm administrator in a group holding RealmOwner, with the API. Everything on the gateway’s side is a setting you give it when it starts.
  • For certificate-bound tokens, a TLS front end that checks client certificates and forwards the one it saw.

A proof is a short signed token the client makes for each request with its private key. It names the request’s method and address and the access token it comes with. A client presents a bound token under the DPoP scheme, with its proof in the DPoP header:

GET /orders/42 HTTP/1.1
Host: api.example.com
Authorization: DPoP eyJhbGciOiJFUzI1NiIsInR5cCI6ImF0K2p3dCJ9.eyJjbmYiOnsiamt0Ijoi…
DPoP: eyJ0eXAiOiJkcG9wK2p3dCIsImFsZyI6IkVTMjU2IiwiandrIjp7…

The proof must name this request’s method and address and this token, be at most a minute old, and use ES256, PS256 or RS256. A proof is taken once: the gateway refuses a proof it has already taken. With several replicas, see Run it in production.

With a nonce key set, a proof must also carry a nonce the gateway issued. The first request without one is answered with the nonce to use:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: DPoP error="use_dpop_nonce", algs="ES256 PS256 RS256", resource_metadata="https://api.example.com/.well-known/oauth-protected-resource"
DPoP-Nonce: <nonce>

The client makes a new proof carrying the nonce, and sends the request again. A nonce lasts five minutes, and every allowed answer to a DPoP request carries the next one, so a client meets the refusal once, not each time a nonce ages out. Give every replica the same key file, and a nonce one replica gives is good at all of them. Treat a nonce as an opaque string.

A nonce also cures a wrong clock: a proof that carries a fresh nonce is taken even when its time is up to 24 hours off, since the nonce, not the client’s clock, shows it’s fresh.

A token bound to a client certificate carries the certificate’s thumbprint (cnf.x5t#S256). The gateway takes it only when the request came over that certificate. TLS ends in front of the gateway, so the front end forwards the client certificate in the x-forwarded-client-cert header. With the forwarded-certificate setting on (see Gateway configuration), the gateway reads it. Turn it on only where every request reaches the gateway through that front end. Off, no request carries a certificate, and every certificate-bound token is refused.

  1. Bind the client’s tokens in the realm: an agent’s client is bound by default; for any other, set dpopBoundAccessTokens: true on the client, or follow Bind tokens to a key.
  2. Optionally, set DPOP_REQUIRED=true on the gateway, to refuse every token bound to no key.
  3. Optionally, set DPOP_NONCE_KEY to a key file, the same on every replica, to require nonces.
  4. If clients address the API at another origin than its audience, set PUBLIC_ORIGIN to it: a proof names the address the client used.
  5. For certificate-bound tokens, have your TLS front end forward the client certificate, and turn on the forwarded-certificate setting.
  • Bound means bound. A token bound to a key (cnf.jkt) is taken only under DPoP, beside a proof signed by that key. Sent as a plain bearer token, it’s refused invalid_token. A token bound to no key, sent under DPoP, is refused too.
  • One DPoP header. A request carrying more than one is refused.
  • Required, if you say so. With DPOP_REQUIRED, the challenge is DPoP alone, and the gateway’s metadata says proofs are required.
  • Without nonces, the minute is strict. A proof outside its minute is refused invalid_dpop_proof. With nonces, it’s answered use_dpop_nonce, so the client can retry.
  • Behind your own proxy, the next nonce must be relayed. An allowed ext_authz check carries DPoP-Nonce, and the proxy has to pass it on to the client, as a header it copies from the check onto the answer. A proxy that copies the check’s headers only onto the request to your API never relays it, so behind it the client gets its nonce from the 401 each time one ages out.
  • Running more than one replica? Give every replica the same DPOP_NONCE_KEY, and keep each client on one replica: see Run it in production.
WhatDefaultCan it change?
A proof’s ageAt most a minute, with 5 seconds of clock difference allowedNo
A proof’s algorithmsES256, PS256, RS256No
A nonce’s lifeFive minutesNo
A proof’s clock with a fresh nonceUp to 24 hours offNo
Binding requiredOffDPOP_REQUIRED
Nonces requiredOffDPOP_NONCE_KEY

A client that gets the binding wrong meets a 401 with a DPoP challenge, and the reason in error. A client that needs a nonce gets it in DPoP-Nonce on that 401, and retries once. The errors, and what the client does about each, are under Errors.

SymptomCauseFix
A bound token is 401 invalid_tokenIt was sent as BearerSend it as Authorization: DPoP <token>, with a proof in DPoP
Every proof is 401 invalid_dpop_proofThe proof’s htu names another address than the gateway expects: clients call an origin other than the audience’sSet PUBLIC_ORIGIN to the origin clients call
Proofs fail now and then, without noncesThe client’s clock is more than a few seconds offTurn on nonces: a proof with a fresh nonce is taken whatever the client’s clock says
Behind your proxy, clients meet use_dpop_nonce every few minutesYour proxy doesn’t copy DPoP-Nonce from the check onto its answerCopy it: see Put the gateway behind your proxy
Every certificate-bound token is 401 invalid_tokenThe forwarded-certificate setting is off, or the front end doesn’t forward the certificateTurn the setting on, and forward the certificate in x-forwarded-client-cert

The realm records each bound token it issues as TOKEN_ISSUED, with the key it’s bound to. The gateway’s refusals aren’t on the audit trail yet: each is a warning in the gateway’s own log, with the path and why the proof failed. See Logs and tracing.

Status and reasonWhat it meansWhat the client does
401 invalid_tokenA bound token came as a bearer token, an unbound one came under DPoP, an unbound one came where DPOP_REQUIRED is set, or a certificate-bound token came without its certificate or over anotherPresent the token as its binding requires
401 invalid_dpop_proofThe proof is missing, there’s more than one DPoP header, or the proof doesn’t name this request and token, is too old, uses another algorithm, is signed by another key, or was used beforeMake a new proof for this request
401 use_dpop_nonceThe proof needs the gateway’s fresh nonceRetry with the nonce in DPoP-Nonce
503 dpop_proofs_fullThe gateway is holding too many recent proofsTry again shortly
WhereSettingWhat it does
ClientsecurityProfileAbsent, fapi2 for an agent’s client, whose tokens are bound (oauth2.1 for one that attests)
ClientdpopBoundAccessTokensIssue this client only bound tokens (default off)
GatewayDPOP_REQUIREDRefuse every token bound to no key (default off)
GatewayDPOP_NONCE_KEYThe key nonces are sealed with (unset, no nonce)
GatewayPUBLIC_ORIGINThe origin a proof names for this API (unset, the audience’s)
GatewayThe forwarded-certificate settingRead the client certificate your TLS front end forwards, for certificate-bound tokens (default off)