Skip to content

feat(agent): DPoP-bind the delegated grant to a per-run key - #5706

Merged
kojiwakayama merged 5 commits into
mainfrom
fix/inbox-5141-delegated-dpop-client
Dec 6, 2026
Merged

kojiwakayama merged 5 commits into
mainfrom
fix/inbox-5141-delegated-dpop-client

Conversation

@kojiwakayama

Copy link
Copy Markdown
Contributor

Problem

Phase 4 of delegated user actions (veryfront/veryfront-issue-inbox#5132) mints admin capabilities only into grants that are sender-constrained with DPoP (RFC 9449). The hosted runtime's delegated API client only knows bearer grants: it has no key, sends no proof, and would send a bound grant as Bearer, which the A23 verifier refuses. C9 (veryfront/veryfront-issue-inbox#5141) adds the runtime side.

Root cause

src/agent/hosted/delegated-user-credential.ts keeps the grant in a private store and presents it as Authorization: Bearer <grant> on every request and renewal. Nothing in the run can prove possession of a key, so the API has nothing to bind a grant to.

Fix

  • New src/agent/hosted/delegated-user-dpop.ts: makes an ECDSA P-256 key pair with extractable: false and signs ES256 dpop+jwt proofs. Every WebCrypto, JSON, encoding and URL intrinsic is captured when the module loads. The public JWK (public members only) and its RFC 7638 thumbprint are made once with the key.
  • registerHostedDelegatedUserCredential starts making the key when the grant is registered and keeps the promise in the same private weak store as the grant. The client, the tools, the tool context and project code have no accessor for it.
  • Each attempt signs a new proof with a random jti, htm, htu (the resolved API URL without query or fragment), iat, and ath (base64url SHA-256 of the grant). A grant whose payload names cnf.jkt is sent as Authorization: DPoP <grant> with a DPoP header and is never downgraded to Bearer (no key means the call fails locally). A grant without cnf is sent as Bearer with no proof, as before, so today's API keeps working. The 401 retry after a renewal signs a new proof. A caller-supplied DPoP header is dropped.
  • Every renewal proves the run's key. With the run invocation token, the proof has no ath, as A24 specifies. When the grant renews itself, ath covers the grant.
  • New bind() on the client: one renewal per run, shared by every client of the run. createAgentRuntime awaits it before tools are offered, so both the capability list and the first tool call see the bound grant. Calls made while it is in flight wait for it. An API that does not bind returns an unbound grant (Bearer, as before). A 404 or a refusal keeps the dispatch grant.
  • The runtime registration now advertises delegated_user_dpop.
  • docs/architecture/native-request-processing.md describes the key, the proofs and the new capability.

Tests

deno task test:file on src/agent/hosted/delegated-user-credential.test.ts, src/agent/hosted/cloud-agent-delegated-user.test.ts, src/agent/service/registration.test.ts, then src/agent/hosted and src/agent/service as a whole. Also deno check, deno lint and deno fmt --check on the touched files.

New tests (each fails on main):

  • the key is made non-extractable (exportKey of the private key rejects for jwk and pkcs8), the header JWK has only public members, and WebCrypto patched after load never sees a proof;
  • no CryptoKey and no thumbprint can be reached from the client, the delegated tools or the request;
  • every call has a fresh jti, the right htm, an htu without query, iat and ath, and verifies against its JWK;
  • a bound grant is never sent as Bearer: not on the first call, not on the 401 retry (which has a new jti), and not for a dispatch grant that is already bound;
  • the first renewal binds (run token as Bearer plus a proof without ath), calls made meanwhile wait for it, binding happens once, and later renewals prove the same key;
  • an API that does not bind (unbound renewal, or 404) keeps the grant as Bearer with no proof;
  • a refused proof (401 whose body and WWW-Authenticate echo the proof and grant) becomes the plain "can no longer act" message, with no proof, grant or run token in the error or logs;
  • the runtime binds before any tool is offered, so the tool list follows the bound grant;
  • the registration advertises delegated_user_dpop.

Existing tests that waited for a renewal by spinning on microtasks now wait on macrotasks, because a renewal now signs a proof first.

Not in this PR

  • The API verifier (A23, veryfront/veryfront-issue-inbox#5134) and binding at renewal (A24, veryfront/veryfront-issue-inbox#5135). This PR can merge first: until the API binds, grants stay unbound and are sent as Bearer.
  • No DPoP-Nonce handling. Phase 4 uses no server nonce.
  • The phase 4 tools (C10, C11).

Refs veryfront/veryfront-issue-inbox#5141

🤖 Generated with Claude Code

Each hosted run with a delegated grant gets a non-extractable ECDSA P-256
key, kept in the grant's private store. Every renewal proves it, the run
binds its grant with one renewal before tools are offered, and a grant
that names cnf.jkt is sent only as Authorization: DPoP with a fresh proof
(jti, htm, htu, iat, ath). Unbound grants stay Bearer, so today's API
keeps working. The runtime registration advertises delegated_user_dpop.

Refs veryfront/veryfront-issue-inbox#5141

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kojiwakayama
kojiwakayama deployed to pull-request-auto-merge December 5, 2026 22:03 — with GitHub Actions Active
@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

📦 Client bundle boundary

Entrypoint Modules Source size Server leaks
src/index.client.ts 66 371 KiB ✅ 0
src/react/components/Head.tsx 5 74 KiB ✅ 0
src/react/router/index.tsx 5 74 KiB ✅ 0
src/react/context/index.tsx 5 74 KiB ✅ 0
src/react/fonts/index.ts 6 81 KiB ✅ 0
src/react/components/ui/index.ts 111 720 KiB ✅ 0
src/react/components/ui/adapter/contract.ts 1 18 KiB ✅ 0
src/react/components/ui/icons/index.ts 3 17 KiB ✅ 0
src/chat/index.ts 305 2059 KiB ✅ 0
src/chat/ag-ui.ts 61 464 KiB ✅ 0
src/chat/protocol.ts 1 11 KiB ✅ 0
src/chat/types.ts 46 248 KiB ✅ 0
src/chat/message-prep.ts 80 588 KiB ✅ 0
src/markdown/index.ts 6 30 KiB ✅ 0
src/mdx/index.ts 2 2 KiB ✅ 0
src/agent/identity-contracts.ts 1 3 KiB ✅ 0
src/schemas/index.ts 43 222 KiB ✅ 0
src/platform/env.ts 5 55 KiB ✅ 0
src/workflow/claude-code/react/index.ts 9 91 KiB ✅ 0
src/events/index.ts 37 631 KiB ✅ 0
src/events/ag-ui/public.ts 36 624 KiB ✅ 0
src/run-events/index.ts 54 323 KiB ✅ 0

A server module in a client graph aborts hydration in the browser. New leaks fail CI; known leaks are tracked in scripts/lint/client-bundle-baseline.json to burn down.

A lowercase standard method such as "post" goes out as POST, but the
proof named "post", so an API that checks htm would refuse a bound grant.
The snapshot now normalizes the method the way fetch does, so the proof
and the request agree.

Refs veryfront/veryfront-issue-inbox#5141

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.86784% with 23 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/agent/hosted/delegated-user-credential.ts 89.24% 9 Missing and 1 partial ⚠️
src/agent/hosted/delegated-user-dpop.ts 92.68% 4 Missing and 5 partials ⚠️
src/agent/hosted/cloud-agent-chat-execution.ts 50.00% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@kojiwakayama
kojiwakayama marked this pull request as ready for review December 5, 2026 22:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-05T23:25:37.621238Z 09c9c81 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 63a28dc28d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

… global fetch

The semantic unit-boundary audit counts withMockFetch as a network effect.
Replacing only the trusted host transport keeps the test hermetic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 34ef3648df

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@kojiwakayama kojiwakayama added the blocked Waiting on something label Dec 5, 2026
@kojiwakayama
kojiwakayama deployed to pull-request-auto-merge December 5, 2026 23:08 — with GitHub Actions Active
@kojiwakayama
kojiwakayama disabled auto-merge December 5, 2026 23:08
Bun upper-cases every fetch method while Deno and Node leave patch as is, so
a lower-case method reached the API spelled differently from the proof's htm
on Bun. The client now sends the method upper-cased and signs that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 09c9c8140e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@kojiwakayama kojiwakayama removed the blocked Waiting on something label Dec 5, 2026
@kojiwakayama
kojiwakayama deployed to pull-request-auto-merge December 5, 2026 23:42 — with GitHub Actions Active
@kojiwakayama
kojiwakayama added this pull request to the merge queue Dec 5, 2026
@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

Merged via the queue into main with commit 4f976a5 Dec 6, 2026
445 checks passed
@kojiwakayama
kojiwakayama deleted the fix/inbox-5141-delegated-dpop-client branch December 6, 2026 00:05

This branch was successfully deployed

1 active deployment
pull-request-auto-merge — 09c9c814 Deployed Dec 5, 2026 by kojiwakayama via arm or hold auto-merge #25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant