Skip to main content

JOSE signing and Session JWTs

The runnable session-jwt Pydantic AI example signs and verifies a Session JWT, rejects its replay, and exposes only boolean policy evidence to the model. It is the reference example for the host/model boundary described below.

Both SDKs implement the asymmetric cryptographic operations of version 0.4:

  • JoseSigner signs client assertions and delegations with a key from jwks_uri, with ES256 or PS384. Its purpose sets the header's typ: JWT for a client assertion, poppy-delegation+jwt for a delegation.
  • DelegatedSessionSigner (pap.sessionSigner) keeps one delegated P-256 key per tenant, issuer and User ID, and signs a fresh Session JWT with it for each request. The JWT is ES256 and carries its delegation in poppy_dlg.
  • BlindJoseSigner is a pap.signer that signs client assertions and delegations blindly (RFC 9474), so each is an ordinary PS384 signature.
  • JoseDpopProver is a pap.dpopProver that signs each request's DPoP proof with a key of its own, one per User ID.
  • WebBotAuthSigner is a pap.operatorSigner that signs each request's operator signature with an Ed25519 key the operator publishes (see Operator signatures).
  • verify_session_jwt / verifySessionJwt verify the delegation, then the signature, the method, URL, issuance window, access-token hash and replay state.

ES256 is the default. PS384 is what blind signing produces. A company MUST accept ES256 and SHOULD accept PS384; the reference companies accept both, and nothing else: RS256, symmetric algorithms and none are rejected even if the underlying JOSE library supports them.

token_endpoint_auth_signing_alg_values_supported in the issuer's metadata describes client assertions only: it says nothing of delegation signatures, which have no discovery field, and invalid_session doesn't tell an unsupported algorithm from any other failure. An agent that needs blind signing may be unable to work with a company that doesn't support PS384.

A DPoP proof is a separate signature by a separate key: see DPoP.

In TypeScript, import device-side DelegatedSessionSigner and BlindJoseSigner from the portable package entry. Import JoseSigner, verifySessionJwt, and the replay-cache contracts from @datalayer/personal-agent-protocol/server. This enforced entry split keeps a key from jwks_uri and the company's checks out of browser bundles; it does not make an in-process Node private key equivalent to KMS/HSM custody.

Key custodyโ€‹

The local signers receive an asymmetric private key object. The signer keeps delegated keys in a DelegatedKeyCustody (current, replace, forget, by tenant, company issuer, and User ID). A User ID's key is made on first use with a delegation that lasts delegation_lifetime (delegationLifetime, one hour by default, at most 24 hours), and is replaced by a new key and delegation rotate_before (rotateBefore, five minutes by default) the delegation's expiry. A Session JWT is never signed after its delegation's exp.

Rotate delegated keys as often as you like: each Session JWT carries its own delegation, so companies don't depend on a delegated key lasting. Rotate DPoP keys as often as you like too, one per User ID (DpopKeyCustody.forget, then refresh): the next refresh sends a proof with the new key, and the new access token is bound to it. Rotating either doesn't affect refresh tokens, which are tied to the client_id, not to a key.

Each delegated key signs for one User ID only, so its thumbprint and its delegation's jti name one User at one Company. A delegation names no User and no Company. InMemoryDelegatedKeys is for tests and examples; a host contributes durable, protected custody. cnf.jwk holds only the public key; a JWK with any private member is rejected.

For local development, an in-process private key is sufficient. TypeScript can also use a non-exportable Web Crypto key in trusted device code. Production hosts using an HSM, KMS, or another remote custody service should contribute their own Reactor signer and delegated key custody. Never place private JWKs, PEM values, Session JWTs, assertions, or access tokens in configuration returned to a browser, logs, analytics, tool arguments, or model context.

Blind signing and what it gives upโ€‹

A key that signs blindly never sees what it signs. The device writes the JWT, draws its jti, blinds the signing input with RSABSSA-SHA384-PSS-Deterministic, and sends only the blinded message to a BlindSigningKey. It unblinds the answer into an ordinary PS384 signature, which any company verifies like another. The key holder never learns which company a client assertion names, and can't recognize a delegation it signed when a company shows it. RsaBlindSigningKey is a reference holder, with an RSA key of at least 2048 bits (3072 suggested).

The privacy has a price, which spec 10.7 states and a host has to accept before it turns this on:

  • The signature stops meaning approval. A key that signs blindly signs whatever a device sends it, and a company accepts any client assertion or delegation that verifies. So a device that can get blind signatures can get any client assertion or delegation the agent could issue. The agent MUST NOT rely on a signature to mean its own systems approved what was signed, for example to limit delegation lifetimes or to stop a User.
  • Both or neither. For the same reason, an agent that signs blindly MUST sign both its client assertions and its delegations blindly. One BlindJoseSigner does both.
  • Any User can authenticate as the agent. A refresh token works only with a client assertion from its client, and an access token only with a Session JWT from its client. With blind signing any User of the agent can make either, so a token stolen from one User works for any other User of the same agent. The same holds whenever devices can get client assertions, blindly or not. Keep refresh and access tokens on the User's device, protected like its other secrets.
  • Signatures need a limit. The key holder still sees when a User asks for a signature, and has nothing else to go on. Limit how many signatures each User can get, in the holder. The SDK's reference holder has no such limit.
  • The jti carries the safety. The deterministic variant adds no randomness to the message, so it is safe only because the message holds a value the signer can't guess. The jti MUST be drawn on the User's device. BlindJoseSigner refuses a jti too short to be one.

Unless its own systems need to see which companies a User works with, the spec says an agent SHOULD sign blindly. The SDKs' default signer doesn't: running blind is the host's choice, and it needs a BlindSigningKey of its own.

DPoPโ€‹

Whether a company binds its access tokens with DPoP (RFC 9449) is its choice (spec 4.5), and the spec says a personal agent SHOULD support it. Both SDKs do.

  • Keys. pap.dpopProver signs each proof. Its default, JoseDpopProver, keeps one P-256 key per User ID (tenant, issuer and sub) in a DpopKeyCustody, as the spec asks of DPoP keys for the same reason as delegated keys (spec 4.5, 5.2): a key shared by two User IDs would let its thumbprint link them. So each sign-in and refresh at an issuer that lists ES256 names its User ID (pairwise_user_id, pairwiseUserId). Never a delegated key and never one from jwks_uri: a proof and a Session JWT are separate signatures with separate keys (spec 5.2). The default custody, InMemoryDpopKeys, is for one process; the Python pap CLI keeps its keys in its key file.
  • A proof has typ dpop+jwt, alg ES256 and the public jwk in its header, and jti (128 random bits), htm, htu without query or fragment, and iat in its claims, with ath when an access token goes and nonce when the server gave one.
  • Token requests send a proof when the issuer's dpop_signing_alg_values_supported includes ES256, and only then: a company that lists nothing, or a list without ES256, gets exactly the request it got before. At MCP, Bearer is the baseline: a token for an MCP server carries a proof only when that server's protected resource metadata lists ES256, whatever the issuer lists. use_dpop_nonce with a DPoP-Nonce header is retried once, with a fresh proof and a fresh client assertion.
  • Token responses can be Bearer or DPoP, ignoring case. Binding is the company's choice, so Bearer after a proof is fine. DPoP when no proof went is refused (unsupported_token_type).
  • Resources. A DPoP token goes as Authorization: DPoP, with a proof whose ath covers it and the Session header, whose ath covers the same token. Each request and retry has a fresh proof and a fresh Session JWT. A 401 DPoP error="use_dpop_nonce" is retried once, and the latest DPoP-Nonce is kept per origin in the transport.
  • Refresh tokens aren't bound (RFC 9449 ยง5, a confidential client). A lost key means refreshing, which gets a token for a new key, not signing in again.

Both reference companies bind their tokens when configured to, with dpop_binding (dpopBinding; see the company guide); by default they issue Bearer tokens and list no DPoP algorithm. A Session JWT's ath already makes a copied access token useless without the agent's delegated key, except at an MCP server that ignores the Session header.

Operator signaturesโ€‹

A personal agent SHOULD also sign requests that carry the Session header with an HTTP Message Signature (RFC 9421), using Web Bot Auth (spec 5.3), so a company's bot defenses can recognize the operator before its application sees the request. It is compatibility support, not a credential. Both SDKs sign when the host asks; a host that contributes nothing sends what it always sent, and its Session JWTs are as valid as ever.

from personal_agent_protocol import WebBotAuthSigner, new_operator_key, operator_directory

key = new_operator_key() # or your own: a KMS key is any OperatorSigningKey
signer = WebBotAuthSigner(key, signature_agent="https://agent.example/operator-keys.json")
# Contribute `signer` to OPERATOR_SIGNERS, and serve operator_directory([key]) at that URL.
  • Keys. pap.operatorSigner has no default: the key is the operator's, and it means nothing until the operator publishes it. operator_directory (operatorDirectory) is the JWK Set to serve at the Signature-Agent URL: any HTTPS URL, or /.well-known/http-message-signatures-directory with its media type to name a domain. Keep operator keys apart from delegated keys, DPoP keys and keys in jwks_uri. Rotate by publishing the new key beside the old one.
  • Where it runs. A centralized agent signs where its requests already pass. Don't give devices a shared operator key: for an on-device agent, a signing service sees which company each User visits, and this profile has no blind signing. That is why the pap CLI signs nothing.
  • What is signed. Last, over the finished headers, on every request and retry: @authority, the Signature-Agent member, @method, @path, @query, poppy-session, and authorization when present, tagged web-bot-auth, with created, expires (a minute later), keyid, alg="ed25519" and a nonce. The body isn't covered: Content-Digest is for a verifier that relies on it.
  • Other drafts. Signature-Agent is the dictionary form of draft 01. Check what the receiving edge supports: products don't all implement one revision.

A reference company checks signatures with operator_signatures (operatorSignatures), its choice. A verified signature authenticates its key source and nothing else: it says nothing of client_id, and the Session JWT is verified first, whatever a signature says.

Replay cache contractโ€‹

Verification requires an atomic replay-cache implementation. Its mark_once / markOnce operation receives a key, composed from the agent's client_id and the JWT's jti, plus an expiry. It must return true exactly once across every process that can accept requests for that company. An ordinary per-process map is appropriate only for tests.

The expiry is the last moment the verifier would still accept the identifier: a Session JWT's iat plus the acceptance window, a client assertion's exp plus the 30-second clock skew. A cache must refuse the identifier until then and may forget it after: the default MemoryReplayCache sweeps expired identifiers whenever it has doubled, so it holds about twice those still alive. check_replay_cache / checkReplayCache (personal_agent_protocol.company.testing, the ./server entry) checks a cache: of many callers marking one identifier at once, exactly one wins. See Load tests.

Rejecting a reused Session JWT jti is a choice the spec leaves to the company; the reference companies make it. The verifier checks replay state last, after signature and binding validation, so invalid traffic cannot fill the replay cache with attacker-chosen IDs.

URL and token bindingโ€‹

A Session JWT's htu excludes query and fragment, while htm uses the uppercase HTTP method. A request with an access token carries ath, the base64url SHA-256 hash of the exact token; a request without one must omit it. The verifier also checks that the token was issued to the JWT's iss.

Delegated keys bind nothing a company stores. Sessions are named by client_id and sid, and refresh tokens by client_id, so a company never expects a delegated key to stay the same between requests or Sessions. It may remember which User ID a delegated key signed for while a delegation for it lasts, and refuse the key for another User ID with invalid_session (spec 5.2), which limits a leaked delegated key to one User; the reference company does. A browser join is authorized by a request carrying the Session header, not by a proof over its code.