@agent-custody/receipts 0.16.12 → 0.16.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,6 +53,11 @@ export declare function normalizeAuthority(host: string): string;
53
53
  * component or component parameter is refused rather than guessed at.
54
54
  */
55
55
  export declare function signatureBase(req: SignedRequest, input: SfInnerList): string;
56
+ /**
57
+ * True when a `Content-Digest` field (RFC 9530) holds a sha-256 or sha-512 digest of `body`, and every such digest it
58
+ * holds matches. A field with neither, or one that does not parse, is false.
59
+ */
60
+ export declare function contentDigestMatches(field: string | undefined, body: Uint8Array): boolean;
56
61
  /** The RFC 7638 thumbprint of an Ed25519 JWK (RFC 8037 appendix A.3): the base64url SHA-256 of `{"crv","kty","x"}`. */
57
62
  export declare function jwkThumbprint(x: string): string;
58
63
  export interface WebBotAuthOptions {
@@ -79,7 +84,8 @@ export type SignatureCheck = {
79
84
  outcome: "verified";
80
85
  agent: string;
81
86
  keyid: string;
82
- label: string;
87
+ label: string; /** the components the signature covered whole (no parameters), as named in Signature-Input */
88
+ covered?: string[];
83
89
  } | {
84
90
  outcome: "invalid" | "unavailable";
85
91
  error: string;
@@ -89,8 +95,8 @@ export type SignatureCheck = {
89
95
  outcome: "unchecked" | "absent";
90
96
  };
91
97
  export interface WebBotAuthVerifier {
92
- /** `grantAgent`: the agent of the request's grant, when a trusted principal signed it; a did:key signature keeps its nonce only for that agent */
93
- verify(req: SignedRequest, grantAgent?: string): Promise<SignatureCheck>;
98
+ /** `keyAgents`: the did:key, or did:keys, that a trusted grant or a trusted registry's passport in the request names; a did:key signature keeps its nonce only for one of them */
99
+ verify(req: SignedRequest, keyAgents?: string | readonly string[]): Promise<SignatureCheck>;
94
100
  /** nonces held now, or undefined when the nonce store does not count them */
95
101
  nonces(): number | undefined;
96
102
  }
@@ -277,6 +277,33 @@ export function signatureBase(req, input) {
277
277
  lines.push(`"@signature-params": ${serializeMember(input)}`);
278
278
  return lines.join("\n");
279
279
  }
280
+ /**
281
+ * True when a `Content-Digest` field (RFC 9530) holds a sha-256 or sha-512 digest of `body`, and every such digest it
282
+ * holds matches. A field with neither, or one that does not parse, is false.
283
+ */
284
+ export function contentDigestMatches(field, body) {
285
+ if (!field)
286
+ return false;
287
+ let members;
288
+ try {
289
+ members = parseDictionary(field);
290
+ }
291
+ catch {
292
+ return false;
293
+ }
294
+ let checked = 0;
295
+ for (const alg of ["sha-256", "sha-512"]) {
296
+ const m = members.get(alg);
297
+ if (!m)
298
+ continue;
299
+ if ("list" in m || m.item.t !== "bytes")
300
+ return false;
301
+ if (!createHash(alg.replace("-", "")).update(body).digest().equals(m.item.v))
302
+ return false;
303
+ checked++;
304
+ }
305
+ return checked > 0;
306
+ }
280
307
  /** The RFC 7638 thumbprint of an Ed25519 JWK (RFC 8037 appendix A.3): the base64url SHA-256 of `{"crv","kty","x"}`. */
281
308
  export function jwkThumbprint(x) {
282
309
  return createHash("sha256").update(`{"crv":"Ed25519","kty":"OKP","x":"${x}"}`).digest("base64url");
@@ -411,7 +438,7 @@ export function createWebBotAuthVerifier(opts, f, now = () => Date.now(), nonceS
411
438
  inflight.set(origin, p);
412
439
  return p;
413
440
  };
414
- async function verify(req, grantAgent) {
441
+ async function verify(req, keyAgents = []) {
415
442
  const inputText = req.header("signature-input");
416
443
  const sigText = req.header("signature");
417
444
  if (!inputText && !sigText)
@@ -517,8 +544,8 @@ export function createWebBotAuthVerifier(opts, f, now = () => Date.now(), nonceS
517
544
  if (opts.requireNonce && !nonceP)
518
545
  return invalid(`${label} has no nonce, and this door requires one`, { agent, keyid });
519
546
  // Anyone can make a did:key, so a stranger's signatures must not fill the nonce store. A did:key signature that no
520
- // trusted grant names is never accepted by the door, and its nonce is not kept.
521
- const nonceKey = nonceP && (!didKey || keyid === grantAgent) ? `${agent} ${keyid} ${nonceP.v}` : undefined;
547
+ // trusted grant or passport names is never accepted by the door, and its nonce is not kept.
548
+ const nonceKey = nonceP && (!didKey || (typeof keyAgents === "string" ? keyAgents === keyid : keyAgents.includes(keyid))) ? `${agent} ${keyid} ${nonceP.v}` : undefined;
522
549
  const full = { outcome: "unavailable", error: nonceStore ? "the door's nonce store is full and cannot record another" : `the door holds ${opts.maxNonces} nonces and cannot record another`, agent, keyid };
523
550
  if (nonceKey && nonces.check) {
524
551
  let state;
@@ -562,7 +589,7 @@ export function createWebBotAuthVerifier(opts, f, now = () => Date.now(), nonceS
562
589
  if (claim === "full")
563
590
  return full;
564
591
  }
565
- return { outcome: "verified", agent, keyid, label };
592
+ return { outcome: "verified", agent, keyid, label, covered: covered.filter((c) => c.params.length === 0 && c.item.t === "string").map((c) => c.item.v) };
566
593
  }
567
594
  return { verify, nonces: () => nonces.size?.() };
568
595
  }
@@ -0,0 +1,91 @@
1
+ # Admission lists
2
+
3
+ A site keeps its own named lists of agents, such as `partners` or `blocked`. Its [door](door.md) records in each arrival fact which lists the arrival's agent is on, and its Cedar policy decides what each list means. The decision is a receipt that names the lists and the digest of the lists in force, so a reader knows which version of the lists the door used.
4
+
5
+ To fill a list, a site can search an [agent registry](agent-registry.md) by capability.
6
+
7
+ ## Find agents in the registry
8
+
9
+ The registry answers a search without a session:
10
+
11
+ ```bash
12
+ curl 'https://app.agent-custody.dev/registry/agents?capability=refunds&limit=50'
13
+ # { "registry": "https://app.agent-custody.dev/", "agents": [ <entry>, … ], "next": "agt_…" | null }
14
+ ```
15
+
16
+ It lists active agents only, never a revoked or expired one, ordered by id. `capability` filters by one capability and `owner` by one tenant. `limit` is 1 to 100 (50 by default); any other value is a `400`. To get the next page, send `after=<next>`. `registry` is the registry's URL as its passports name it: copy it into a list entry. Each entry is the one `GET /registry/agents/<id>` publishes, without `contact` or `history`: id, name, owner, capabilities, its key as a did:key and a JWK, and its ERC-8004 link when it has one. A search finds agents; it is not a directory of contacts. An agent's contact is on its own entry and in its passport, which reaches every site the agent visits.
17
+
18
+ The registry's public reads (the search, an agent's entry, and its passport) allow each address a burst of 120 and then one every 2 seconds; past that they answer `429` with `Retry-After`.
19
+
20
+ The registry signs nothing about a search. A site that lists an agent from a search names it by the entry's registry and id, and the door then admits the agent only on a passport the registry signed.
21
+
22
+ ## Write the lists
23
+
24
+ The lists are a JSON file beside the door config:
25
+
26
+ ```json
27
+ {
28
+ "lists": {
29
+ "partners": [
30
+ { "registry": "https://app.agent-custody.dev/", "agentId": "agt_d0cdd11e729cf856" },
31
+ { "erc8004": { "agentRegistry": "eip155:8453:0x…", "agentId": "7" }, "registry": "https://app.agent-custody.dev/" }
32
+ ],
33
+ "crawlers": [{ "agent": "https://crawler.example" }],
34
+ "blocked": [{ "agent": "did:key:z6Mk…" }]
35
+ }
36
+ }
37
+ ```
38
+
39
+ ```json
40
+ { "admissionLists": "admission.json" }
41
+ ```
42
+
43
+ A list name is lowercase letters, digits, and `. _ -`, at most 64 characters. There are at most 64 lists, of at most 10,000 entries each. An entry names an agent in one of three ways, by what the door checks:
44
+
45
+ | entry | matches a `verified` arrival | survives a key rotation |
46
+ | --- | --- | --- |
47
+ | `{ "registry", "agentId", "version"? \| "versions"? }` | whose [passport](agent-registry.md#admit-registered-agents-at-a-door) is `verified`, from that registry, for that agent id | yes |
48
+ | `{ "erc8004": { "agentRegistry", "agentId" }, "registry"? }` | whose `verified` passport carries that [ERC-8004 link](agent-registry.md#link-an-erc-8004-identity), which the registry checked on chain, and, with `registry`, names that registry | yes, while the token's file names the new key |
49
+ | `{ "agent" }` | whose `subject` is that value: a did:key, a Web Bot Auth signature agent's origin, or the agent a trusted grant names | no, for a did:key |
50
+
51
+ A registry entry may also name the agent's versions: `"version": "1.4.0"` for one, or `"versions": { "from": "1.2.0", "below": "2.0.0" }` for a range (`from` included, `below` not, either may be left out). Versions compare as numbers, so 1.10.0 is above 1.2.0. An entry with a version matches only a `verified` passport that carries a version in it; an agent whose owner registered no version is not on the list by that entry. When the agent arrives at a version the list does not name, the receipt shows `passport.agentVersion` and lists without that name, so the site sees the change before it admits it.
52
+
53
+ The registry's URL is part of a registry entry because an agent id is unique only within one registry. A URL or origin is compared in one spelling, so `https://APP.example.test:443` and `https://app.example.test/` name the same registry, and `https://Crawler.Example/` the agent `https://crawler.example`; a did:key is compared exactly.
54
+
55
+ **Bind each registry key to its registry.** A passport's `registry` is written by the registry that signs it. A door that trusts the keys of two registries, each as a bare path, lets either one issue a passport that names the other's URL and an agent id from it, and so put its own agent on a list entry meant for the other's agent. Give each key the one registry it speaks for, `{ "key": "keys/registry.pub", "registry": "https://app.agent-custody.dev/" }` ([the agent registry](agent-registry.md#admit-registered-agents-at-a-door)), and a passport that names any other registry is `invalid`. `agent-custody check` warns when more than one registry key is trusted and any is bound to no URL. The binding protects `{ registry, agentId }` entries, and `{ erc8004 }` entries that name a registry. An `{ erc8004 }` entry trusts the on-chain check of the registry that signed the passport, so without `registry` any registry whose key the door trusts can sign a passport that carries another registry's agent's ERC-8004 identity, and put its own agent on the list by that entry. Add `"registry"` beside `"erc8004"`, the URL of the registry that must vouch for the link, and only a passport that names it matches. An entry without `registry` matches whichever trusted registry vouches, which is safe only when the door trusts one. Prefer registry entries for registered agents, because they survive a key rotation. Use `agent` for an agent with no registry, or to block one key whatever registry vouches for it.
56
+
57
+ The door reads the file when it starts, and refuses to start if the file is not valid. It reads the file again whenever it changes. A changed file that cannot be read, or is not valid, leaves the lists in force and prints `ADMISSION LISTS NOT RELOADED`. Emptying the lists instead would also empty a block list. `agent-custody check --config door.json` checks the file. In a Worker, the lists are the `ADMISSION_LISTS` variable, and a change is a deploy.
58
+
59
+ ## Use them in a policy
60
+
61
+ The door adds `admission` to every arrival fact when it has lists:
62
+
63
+ ```json
64
+ { "admission": { "lists": ["partners"], "digest": "c34ef919ab97…" } }
65
+ ```
66
+
67
+ `lists` holds the names of the lists the agent is on, sorted, and is empty when it is on none. `digest` is the sha256 of the lists file in force. The names mean what the policy makes of them:
68
+
69
+ ```cedar
70
+ // a refund is for a verified partner, and never for a blocked agent
71
+ permit(principal, action == Action::"refund", resource)
72
+ when {
73
+ context.facts.arrival.class == "verified" &&
74
+ context.facts.arrival has admission &&
75
+ context.facts.arrival.admission.lists.contains("partners")
76
+ };
77
+ forbid(principal, action == Action::"refund", resource)
78
+ when { context.facts.arrival has admission && context.facts.arrival.admission.lists.contains("blocked") };
79
+ ```
80
+
81
+ A `forbid` beats a `permit`, so an agent that is a partner by its registry entry and blocked by its key is refused. Test `has admission`, because a door without lists, or a receipt from before the lists, has no such field.
82
+
83
+ ## What puts an agent on a list
84
+
85
+ Only what the door checked. An arrival that is not `verified` is on no list. A passport under another key's signature, or under a signature that does not bind it to the request, does not put the registry's agent on a list, even when the arrival is verified as itself by its own grant. A claim therefore cannot add an agent to an allow list. A policy that blocks with `forbid` must not rely on a claimed arrival being listed: such an arrival is on no list, so refuse it some other way, for example by permitting only `verified` arrivals, as above.
86
+
87
+ ## What it does not do
88
+
89
+ - **Lists live in the door's config, not the registry.** The registry holds agents; each site keeps its own lists in its own file, so no one else can change who a site admits. There is no shared list service.
90
+ - **Lists do not deny or allow on their own.** Every meaning comes from the policy.
91
+ - **The digest names a version of the lists, not the lists themselves.** To read what a receipt's lists said, keep each version of the file, for example in version control.
@@ -0,0 +1,191 @@
1
+ # The agent registry
2
+
3
+ An organisation that runs agents registers each one on the portal, and the portal signs it a **passport**. A site whose [door](door.md) trusts the registry's key admits that agent as `verified`. The site needs nothing per agent, and the door asks the registry nothing when a request arrives.
4
+
5
+ ## What a passport is
6
+
7
+ A passport is a DSSE envelope of type `application/vnd.agent-custody.passport+json`, signed by the registry's key:
8
+
9
+ ```json
10
+ {
11
+ "version": "0.1",
12
+ "registry": "https://app.agent-custody.dev/",
13
+ "agentId": "agt_5325ae63b111bdcb",
14
+ "agent": "did:key:z6Mkn6Tz2tjzcb8f…",
15
+ "name": "Carted shopper",
16
+ "owner": "carted",
17
+ "contact": "agents@carted.example",
18
+ "capabilities": ["refunds"],
19
+ "agentVersion": "1.4.0",
20
+ "endpoints": ["api.stripe.com", "https://mcp.carted.example/mcp"],
21
+ "issuedAt": "2026-11-23T09:00:00.000Z",
22
+ "expiresAt": "2026-11-24T09:00:00.000Z"
23
+ }
24
+ ```
25
+
26
+ - `agent` is the agent's own Ed25519 key, written as a [did:key](https://w3c-ccg.github.io/did-key-spec/). The agent holds the private key; the registry never sees it.
27
+ - `owner` is the portal tenant that registered the agent. `contact` is how a site reaches the agent's operator.
28
+ - `capabilities` are the organisation's own words for what the agent does: lowercase letters, digits, and `. _ : -`, at most 32. The registry does not check them. A site's policy decides what they are worth.
29
+ - `agentVersion`, when the owner registered one: the agent's version, `MAJOR.MINOR.PATCH`, numbers only. `version` is the passport format's own.
30
+ - `endpoints`, when the owner declared any: the tool endpoints the agent says it calls, host names or https or wss URLs (an MCP server), at most 32. They are a claim: the registry does not check them, and only an [egress witness](egress.md) on the agent's own host can show what it really calls.
31
+ - A passport lives for a day by default (`--passport-seconds`, from 60 seconds to 7 days), and never past the registration's own expiry.
32
+ - `erc8004`, when the agent is [linked to an ERC-8004 identity](#link-an-erc-8004-identity): `{ agentRegistry, agentId, owner, block }`, as the registry last checked it on chain.
33
+
34
+ **A passport is public.** It proves nothing without a signature by the agent's key on the same request, so the registry serves one to anyone who asks, like a certificate.
35
+
36
+ ## Register an agent
37
+
38
+ The portal runs the registry when it starts with a registry key, and `--portal-url`, which names the registry in every passport:
39
+
40
+ ```bash
41
+ agent-custody keygen --dir keys --name registry
42
+ export REGISTRY_KEY="$(cat keys/registry.key)"
43
+ agent-custody portal --db-env DATABASE_URL --secret-env PORTAL_SECRET --public-url https://log.example/ \
44
+ --portal-url https://app.example/ --registry-key-env REGISTRY_KEY
45
+ ```
46
+
47
+ The registry key is its own, never the log's. To keep it out of the process that faces the internet, hold it in a signer, `agent-custody signer --key keys/registry.key --port 8791 --token-env REGISTRY_SIGNER_TOKEN`, and start the portal with `--registry-signer-url http://signer:8791/ --registry-signer-token-env REGISTRY_SIGNER_TOKEN` instead.
48
+
49
+ An admin of a tenant registers an agent with the agent's did:key, a proof that whoever registers it holds that key, a contact, its capabilities, and an expiry at most 366 days out. The agent's operator makes the proof with the agent's private key:
50
+
51
+ ```bash
52
+ agent-custody registry proof --key agent.key --registry https://app.example/ --tenant carted
53
+ # {"agent":"did:key:z6Mk…","proof":"…"}
54
+ curl -b session.txt -H 'content-type: application/json' https://app.example/api/agents \
55
+ -d '{ "name": "Carted shopper", "contact": "agents@carted.example", "capabilities": ["refunds"],
56
+ "agent": "did:key:z6Mk…", "proof": "…", "expiresAt": "2027-02-21T00:00:00Z" }'
57
+ ```
58
+
59
+ The proof is the key's Ed25519 signature over the registry's URL, the tenant, and the did:key (`registrationProof` in code), so it registers that key with that tenant at that registry only. Without it, a tenant could register a did:key it saw in a grant or a signature and choose that agent's capabilities. A key rotation needs the new key's proof.
60
+
61
+ The answer has the registry entry and a first passport. Every key belongs to one live agent, which the database enforces, and a tenant has at most 100 agents that are not revoked. An expired agent counts until it is revoked. `POST /api/agents/<id>` changes the name, contact, capabilities, key, or expiry, and `POST /api/agents/<id>/revoke` revokes the agent for good. Each is in the tenant's audit trail. The [hosted reference](../../../site/reference/hosted.md) lists every route.
62
+
63
+ In code, `didKeyOf(publicKey)` gives a key's did:key.
64
+
65
+ ### Versions and declared endpoints
66
+
67
+ A registration, and a change to one, may carry `version` (`MAJOR.MINOR.PATCH`, or `null` for none) and `endpoints` (the tool endpoints the agent says it calls: at most 32, and at most 1,024 characters together, so that a passport with the largest of every other field still fits the 8,192 characters a door reads; a URL is stored as its `href`, and white space and control characters are refused). The entry keeps the agent's history: each change of version, and each key rotation, closes the stretch the agent was in, and the entry records it, newest first, as `{ version, agent, from, to }`. `replaces` is the version the current one replaced. A change of name, contact, capabilities, or expiry leaves the history alone. The entry keeps the last 100 stretches. Two changes made at once to one agent do not both land: the one that reads a version or key that another has just replaced is refused with "read the entry again and retry".
68
+
69
+ ```bash
70
+ curl -b session.txt -H 'content-type: application/json' https://app.example/api/agents/agt_5325ae63b111bdcb -d '{ "version": "1.5.0" }'
71
+ # { "agent": { …, "version": "1.5.0", "replaces": "1.4.0", "history": [ { "version": "1.4.0", "agent": "did:key:z6Mk…", "from": "…", "to": "…" } ] }, "passport": … }
72
+ ```
73
+
74
+ A site that admits one version of an agent names it in its [admission list](admission-lists.md#write-the-lists) with `version` or `versions`. When the agent arrives at a later version, its receipt records `passport.agentVersion` and that no list named it.
75
+
76
+ ## Link an ERC-8004 identity
77
+
78
+ An agent that already has a token in an [ERC-8004](https://eips.ethereum.org/EIPS/eip-8004) Identity Registry can carry it in its passport. The registry vouches for the agent, as before; the link adds the agent's portable on-chain identity, so a site can require one. ERC-8004 is still a draft, and only its `registration-v1` file is read.
79
+
80
+ The portal reads a chain only with an RPC URL for it, from the environment:
81
+
82
+ ```bash
83
+ export BASE_RPC="https://…" # a provider's URL often carries its key
84
+ agent-custody portal … --registry-key-env REGISTRY_KEY --erc8004-rpc-env 8453=BASE_RPC [--ipfs-gateway https://ipfs.io]
85
+ ```
86
+
87
+ The owner adds `"erc8004": { "agentRegistry": "eip155:8453:0x…", "agentId": "7" }` to `POST /api/agents` or `POST /api/agents/<id>`. `agentId` is the token id in decimal. Before it stores the link, the registry reads, at one block:
88
+
89
+ 1. `ownerOf(agentId)`: the token exists and has an owner.
90
+ 2. `tokenURI(agentId)`: where the registration file is. It fetches the file: an inline `data:application/json` URI, `https://` (never from an internal address, following no redirect, within 5 seconds and 64 KiB), or `ipfs://` through `--ipfs-gateway`, as a CID and plain path segments that stay under the gateway's `/ipfs/<cid>/`; a `.` or `..` segment is refused.
91
+ 3. The file: its `type` is `registration-v1`, `active` is true, `registrations` lists this `agentRegistry` and `agentId`, and `services` has `{ "name": "DID", "endpoint": "<the agent's did:key>" }`.
92
+
93
+ So the agent's owner publishes its did:key in the token's registration file first. Anything that does not agree is refused with the reason. The entry records the owner address, the block, the file's sha256, and when it was checked. A new key while a link stands is checked against the file again, so rotate the key in the file first. `"erc8004": null` unlinks.
94
+
95
+ A link is checked again before a passport carries it, when the last check is older than `--erc8004-recheck-seconds` (an hour by default, 60 to 86400), at most once a minute per agent. When that check fails, for example because the owner marked the agent inactive or moved the token to a file that no longer lists the key, passports carry no link until a check succeeds, and the entry shows the error. A check that finishes after the owner changed the link or rotated the key is not stored: it was for a link the agent no longer has.
96
+
97
+ The door reads no chain. It records the link from the passport in `arrival.passport.erc8004`, only when the passport is `verified`, bound to the request by the agent's signature; a passport under another key carries no link into the policy. A policy can require it, testing the outcome too:
98
+
99
+ ```cedar
100
+ permit(principal, action == Action::"refund", resource)
101
+ when {
102
+ context.facts.arrival.class == "verified" &&
103
+ context.facts.arrival has passport &&
104
+ context.facts.arrival.passport.outcome == "verified" &&
105
+ context.facts.arrival.passport has erc8004 &&
106
+ context.facts.arrival.passport.erc8004.agentRegistry == "eip155:8453:0x…"
107
+ };
108
+ ```
109
+
110
+ What the link does not do: it reads the ERC-8004 Identity Registry only, not its Reputation or Validation registries; it does not make anyone's token trustworthy (anyone can register one for gas, which is why the registry still vouches); and a door that trusts ERC-8004 registries directly, with no portal, is not built.
111
+
112
+ ## What the registry publishes
113
+
114
+ | path | what |
115
+ | --- | --- |
116
+ | `GET /.well-known/agent-custody-registry.json` | the registry's key document: its URL, the passport type and header, how long a passport lives, the chain ids whose ERC-8004 registries it reads (`erc8004Chains`), and its keys (`keyid`, `alg`, `publicKeyPem`, `validFrom`) |
117
+ | `GET /registry/agents/<id>` | the agent's entry: name, owner, contact, capabilities, its key as a did:key and as an Ed25519 JWK (`kid` is the did:key, `exp` the registration's expiry), `status` (`active`, `revoked`, or `expired`), and `erc8004`, the linked identity as last checked (with `error` when the last check failed) or null |
118
+ | `GET /registry/agents?capability=&owner=&limit=&after=` | the active agents that hold a capability (or belong to an owner), by id, a page of up to 100 at a time; see [admission lists](admission-lists.md#find-agents-in-the-registry) |
119
+ | `GET /registry/agents/<id>/passport` | a fresh passport for an active agent; `410` for a revoked or expired one |
120
+
121
+ These reads need no session. Each address gets a burst of 120 of them (search, entries, and passports together) and then one every 2 seconds; past that the registry answers `429` with `Retry-After`.
122
+
123
+ The agent fetches a fresh passport before the one it holds expires. It needs no session for that.
124
+
125
+ ## Admit registered agents at a door
126
+
127
+ Put the registry's public key in a file, list it in `trustedRegistryKeys` with the registry's URL (the `registry` of its key document), and configure `webBotAuth`, which checks the agent's signature. Its `agents` may be empty, because a did:key carries its own key and the door fetches nothing:
128
+
129
+ ```json
130
+ {
131
+ "trustedRegistryKeys": [{ "key": "keys/registry.pub", "registry": "https://app.agent-custody.dev/" }],
132
+ "webBotAuth": { "authorities": ["shop.example"] }
133
+ }
134
+ ```
135
+
136
+ A key bound to a registry admits only passports that name that registry, in any spelling of its URL; a passport it signed that names another registry is `invalid`. A registry writes its own URL into its passports, so without the binding a door that trusts two registries lets either one vouch for the other's agents. A bare path, `"keys/registry.pub"`, is still accepted and trusts the key for any registry; `agent-custody check` warns when more than one registry key is trusted and any is bare.
137
+
138
+ The door refuses to start with `trustedRegistryKeys` and no `webBotAuth`. In a Worker the keys are the `TRUSTED_REGISTRY_KEYS` variable: SPKI PEM keys, each trusted for any registry, or a JSON list of `{ "publicKeyPem", "registry" }`, the `keys` of the key document with the registry's URL added to each. In the list, `registry` is required, and a JSON object, such as the whole key document, is refused: its key would otherwise be read bare. One key listed twice, for two registries or bound and also bare, stops the door at start.
139
+
140
+ The agent sends the passport as base64url JSON in `X-Agent-Custody-Passport`, and signs the request as for [Web Bot Auth](door.md#a-did-key-signature): RFC 9421, Ed25519, `tag="web-bot-auth"`, a nonce, and `keyid` set to its did:key. For the passport to count, the signature also covers what binds it to this one request:
141
+
142
+ - `@authority`, `@method`, `@path`, `@query` (the query string, or `?` when there is none), and `x-agent-custody-passport`;
143
+ - on any method but GET, HEAD, and OPTIONS, `content-digest`: a `Content-Digest` field (RFC 9530, `sha-256` or `sha-512`) that the door checks against the body it read.
144
+
145
+ ```
146
+ Signature-Input: sig1=("@authority" "@method" "@path" "@query" "x-agent-custody-passport" "content-digest");created=…;expires=…;keyid="did:key:z6Mk…";alg="ed25519";nonce="…";tag="web-bot-auth"
147
+ ```
148
+
149
+ A passport is public, so without that a signature the agent made for one request, or before it held a passport the door would take, could be sent again with the passport attached. A door in authz mode does not see the body, so it admits a passport on a safe method only. With no grant in the request, the door then records:
150
+
151
+ - `class: "verified"`, and `subject` the agent's did:key, which is the Cedar `principal`;
152
+ - `arrival.passport`, with `outcome: "verified"`, the registry, the registry's keyid, the agent's id, did:key, name, owner, capabilities, expiry, the passport's digest, and the passport itself (`envelope`).
153
+
154
+ Only a `verified` passport puts the registry's entry in the fact. Any other outcome records the outcome, the error, and at most the registry and the did:key the passport names, so a passport the signer is not bound to cannot carry another agent's capabilities into the policy, even on an arrival that a grant or a signature verified.
155
+
156
+ A policy reads the registry's word as a fact. Test that the field is there and that the passport was verified, since an arrival without a passport has none:
157
+
158
+ ```cedar
159
+ permit(principal, action == Action::"refund", resource)
160
+ when {
161
+ context.facts.arrival.class == "verified" &&
162
+ context.facts.arrival has passport &&
163
+ context.facts.arrival.passport.outcome == "verified" &&
164
+ context.facts.arrival.passport.capabilities.contains("refunds") &&
165
+ context.args.body.amount <= 5000
166
+ };
167
+ ```
168
+
169
+ | what arrived | `passport.outcome` | `class` |
170
+ | --- | --- | --- |
171
+ | a passport from a trusted registry, in its window, under a signature by its did:key that covers all of the above | `verified` | `verified` |
172
+ | the same, with a signature that leaves out a component above, or a `Content-Digest` that is not of the body | `unbound` | `claimed` |
173
+ | the same passport under another key's signature, or with no signature | `wrong-sender` | `claimed` |
174
+ | a passport from another registry, edited, expired, or a header that is not a passport | `invalid` | `claimed` |
175
+ | a passport at a door with no `trustedRegistryKeys` | `unchecked` | `claimed` |
176
+ | a grant and a passport | recorded | decided by the grant alone |
177
+
178
+ A replayed request is refused as any Web Bot Auth signature is: the nonce is kept for the passport's did:key, whatever grant the request also carries, so the second use is `invalid`, and the arrival is `claimed`. The nonce is kept too for a passport that is not yet valid at the door, because the registry's clock is ahead, so the request cannot be sent again once its window opens. The signature covers `@query`, so the request cannot be sent again with another query either.
179
+
180
+ ## What the receipt shows
181
+
182
+ The receipt names the agent as `observed`, never `attested`: `agent: { id: "did:key:z6Mk…", provenance: "observed" }`, and the principal is `claimed`, as for any arrival admitted by its signature alone. A reader can check the recorded passport again under the registry's key (`verifyPassport(envelope, [registryKey], timestamp)`), but cannot repeat the check of the request's signature, which the receipt does not carry.
183
+
184
+ ## What it does not do
185
+
186
+ - **Revocation reaches the door when the passport expires.** Revoking an agent stops new passports. The passport the agent already holds works until its `expiresAt`, because the door asks the registry nothing. `--passport-seconds` is that delay; shorten it if a day is too long.
187
+ - **A key rotation is the same.** A passport for the old key works until it expires.
188
+ - **Declared endpoints are the owner's claim, and so is the version.** The registry records them and signs that the owner said so. An [egress witness](egress.md) on the agent's own host is what shows the endpoints it really calls.
189
+ - **Capabilities are the owner's claim.** The registry records what the organisation says the agent does, and signs that it said so. It does not check it.
190
+ - **A passport says who, not on whose behalf.** It does not name a principal or a route. For that, the agent presents a [grant](door.md#presenting-a-passport) from a principal the site trusts, and the door decides by the grant.
191
+ - **Who a site admits is the site's own list.** The registry answers a search by capability (`GET /registry/agents?capability=`), and a site lists the agents it admits or blocks in its door's [admission lists](admission-lists.md).
@@ -8,7 +8,7 @@ The door runs from the gateway's container image. The same image runs every othe
8
8
 
9
9
  ```bash
10
10
  mkdir door-quickstart && cd door-quickstart
11
- IMAGE=ghcr.io/svayatta/agent-custody-gateway:0.16.12
11
+ IMAGE=ghcr.io/svayatta/agent-custody-gateway:0.16.14
12
12
  alias agent-custody='docker run --rm --user "$(id -u):$(id -g)" -v "$PWD":/work -w /work -e TURNSTILE_SECRET $IMAGE'
13
13
  ```
14
14
 
@@ -217,7 +217,7 @@ docker rm -f door site && docker network rm door-quickstart
217
217
 
218
218
  With Node 22 or later, the same page runs the CLI from npm. Four steps change, and every other command stays as it is:
219
219
 
220
- - **The setup.** The alias is `alias agent-custody='npx -y -p @agent-custody/receipts@0.16.12 agent-custody'`, and there is no `IMAGE`.
220
+ - **The setup.** The alias is `alias agent-custody='npx -y -p @agent-custody/receipts@0.16.14 agent-custody'`, and there is no `IMAGE`.
221
221
  - **Step 2.** Start the stand-in site with `node -e 'require("http").createServer((q,s)=>{s.setHeader("content-type","text/plain");s.end(q.method==="GET"?"the sign-up page\n":"thanks, you are signed up\n")}).listen(3000,"127.0.0.1")' &`.
222
222
  - **Step 4.** In `door.json`, the origin is `"http://127.0.0.1:3000"`. The check then gives one warning, not two.
223
223
  - **Step 5.** Start the door with `agent-custody door --config door.json --port 8780 &`.
@@ -0,0 +1,128 @@
1
+ # The door as a WordPress plugin
2
+
3
+ > For a small business with a WordPress site. How the door works is in [the door](door.md). The plugin, its build script, and its smoke test are in [deploy/door/wordpress](../../../deploy/door/wordpress/README.md).
4
+
5
+ A WordPress site on ordinary hosting cannot run the Node door, and it has no proxy to put the door in. So the plugin is a door written in PHP. It decides each comment and each form submission inside WordPress, before WordPress acts on it. It signs a receipt for each decision with a key that stays on the site, and it appends the hash of each receipt to a log. The receipt is a door receipt: issuer kind `door`, framework `wordpress`. `agent-custody verify` checks it with the plugin's public key and the log, as it checks a receipt from any door.
6
+
7
+ The owner does three things: install the zip, connect the plugin to a log, and choose a policy preset.
8
+
9
+ ## Install
10
+
11
+ No release publishes the plugin, and a merge to `main` installs it on no site. You build the zip from the repository and upload it.
12
+
13
+ 1. Build the zip: `deploy/door/wordpress/build.sh` writes `agent-custody-door.zip`.
14
+ 2. In WordPress, go to **Plugins > Add New > Upload Plugin**. Upload the zip and activate the plugin.
15
+ 3. Go to **Settings > Agent Custody Door**.
16
+
17
+ On activation the plugin makes its signing key and a table for its receipts. It protects nothing until it is connected to a log, and it shows a notice until then.
18
+
19
+ The plugin needs WordPress 6.0 or later and PHP 7.4 or later. It has no other dependency: WordPress supplies the Ed25519 functions where PHP does not.
20
+
21
+ ## Connect to the log
22
+
23
+ | setting | value |
24
+ | --- | --- |
25
+ | Log URL | the URL of your tenant on the hosted log, `https://log.agent-custody.dev/t/YOUR-TENANT/`, or the URL of any agent-custody log |
26
+ | Log token | the token of the tenant. To keep it out of the database, put `define( 'AGENT_CUSTODY_DOOR_LOG_TOKEN', '...' );` in `wp-config.php` |
27
+
28
+ When you save, the plugin reads the log's key document (`/.well-known/agent-custody-log.json`) and pins the keys. The page then shows `Connected` and the first 12 characters of each pinned key id. Compare them with the key ids that the log's operator publishes. A log at a new URL is a new log: the plugin reads and pins its keys again.
29
+
30
+ The log gets the hash of each receipt, never the receipt. The receipts stay in the site's database.
31
+
32
+ ## Choose a preset
33
+
34
+ A preset is a Cedar policy text that the plugin ships. PHP has no Cedar engine, so the plugin decides each text in PHP, and the test suite checks each PHP decision against Cedar. The receipt records the digest of the policy text.
35
+
36
+ | preset | who may send a protected form | refuses |
37
+ | --- | --- | --- |
38
+ | **Watch** | all. The plugin records what Humans decides | nothing. Start here, and read the decisions |
39
+ | **Humans** | a visitor who passed the challenge, and a signed-in user on a comment or on one of the more protected paths | a submission without a passed challenge from a visitor who is not signed in; a login, a registration, or a lost password without a passed challenge from anyone |
40
+ | **Strict** | a visitor or a signed-in user who passed the challenge | each submission without a passed challenge |
41
+
42
+ Humans and Strict need a challenge. Make a widget at Cloudflare Turnstile or hCaptcha and enter its site key and its secret. To keep the secret out of the database, put `define( 'AGENT_CUSTODY_DOOR_CHALLENGE_SECRET', '...' );` in `wp-config.php`. Without a site key and a secret, no submission can pass a challenge and nobody can sign in, so the settings form does not take Humans or Strict without them: it keeps Watch and says why.
43
+
44
+ A signed-in user is exempt in Humans for comments and the more protected paths only. `wp-login.php` takes a login, a registration, or a lost password from a sender who is signed in already, so those forms always need the challenge. On a REST path (`/wp-json/...`), a sender is signed in only with the REST nonce, as for WordPress itself.
45
+
46
+ **Challenge hostnames** are the hostnames of the pages that show the widget. Empty means the hostname of the site, with and without `www.`. A token from a page on another hostname fails.
47
+
48
+ ## Put it on a live site
49
+
50
+ Do the first install on a test site, not on the live one.
51
+
52
+ 1. Install the plugin, connect it to the log, and keep Watch. Watch refuses nothing, so a wrong setting stops nobody.
53
+ 2. Send a comment while you are signed in, then sign out and sign in. Look at **The last 20 decisions** on the settings page. The comment has the decision `allow` and must show `logged` in the Log column at once: the site reaches the log, and the token is good. The login has the decision `deny`, because no challenge is set yet, and shows `pending` until the hourly run sends it.
54
+ 3. Download a receipt that shows `logged` from that table and verify it ([Verify a receipt](#verify-a-receipt)).
55
+ 4. Enter the challenge keys and change the preset to Humans.
56
+ 5. In a browser window that is not signed in, sign in and send a comment. Each form must show the widget, and each submission must pass.
57
+ 6. Do the same steps on the live site. Leave Watch on for some days before you change to Humans, and read what Humans would refuse.
58
+
59
+ If step 5 fails and you cannot sign in, see "When the door locks you out".
60
+
61
+ ## What it protects
62
+
63
+ | form | the request | route in the receipt |
64
+ | --- | --- | --- |
65
+ | Comments | `POST /wp-comments-post.php`, a trackback (`/wp-trackback.php`), and the REST route that makes a comment (`/wp-json/wp/v2/comments`) | `comment` |
66
+ | Login | `POST /wp-login.php`, with no `action` or with an `action` that WordPress does not know: WordPress signs in on each of them | `login` |
67
+ | Registration | `POST /wp-login.php?action=register`, and `/wp-signup.php` on a network | `register` |
68
+ | Lost password | `POST /wp-login.php?action=lostpassword` | `lostpassword` |
69
+ | More protected paths | a request to a path in the list, exact or with `/*` at the end | `form` |
70
+
71
+ Each stock form has a checkbox. The plugin puts the challenge widget in each protected stock form. **More protected paths** is for the forms of other plugins, for example `/wp-json/contact-form-7/*`. With a path in the list, the plugin also puts the widget in each form on a page that posts to the site, so the token goes with the form's fields. A client that is not a browser sends the token in the `X-Agent-Custody-Challenge` header.
72
+
73
+ The door decides each request that is not a `GET`, a `HEAD`, or an `OPTIONS`, and each request that asks the REST API for another method (`_method`, `X-HTTP-Method-Override`). A path in the list starts after the site's address: on a site at `https://example.com/blog/`, write `/wp-json/contact-form-7/*`. The door compares paths as WordPress and the web server read them, so these all match that entry: `//WP-JSON/Contact-Form-7/...`, `/index.php/wp-json/contact-form-7/...`, and `/?rest_route=/contact-form-7/...`. An exact entry also matches with a `/` at the end, and an entry for a script matches the script with a path after it.
74
+
75
+ ## What happens to a submission
76
+
77
+ 1. The plugin reads the challenge token and asks the provider if it is good. The outcome is `passed`, `failed`, `unavailable`, or `absent`.
78
+ 2. It records the arrival fact: the class (`unknown`, or `claimed` when the request names an agent or presents a grant, a signature, or a passport), the address, the method, the path, the route, and the challenge outcome. It records a second fact, `wordpress`, with `loggedIn`.
79
+ 3. The preset decides. In Watch, a submission that Humans does not allow goes on to WordPress. Like a refused submission, it makes no request to the log and gets no authorization, and its receipt waits for the flush.
80
+ 4. **Refused:** the visitor gets a 403 page with the receipt id. The plugin signs the receipt (`denied`) and stores it as `pending`. It makes no request to the log for a refused submission: the hourly flush appends the receipt.
81
+ 5. **Allowed:** the plugin signs an authorization and commits it to the log. Only then does WordPress get the request. When WordPress has answered, the plugin signs the receipt, with the authorization and the status that WordPress answered (`executed`, or `failed` for a 5xx), and appends it to the log.
82
+
83
+ Each answer has `X-Agent-Custody-Receipt` and `X-Agent-Custody-Class`.
84
+
85
+ **When the log does not answer.** A submission that the preset allows is not passed to WordPress: the visitor gets a 503, and the receipt says `withheld`. The evidence must exist before the effect. In Watch, the submission goes on without the authorization, and the PHP error log says so. A receipt that the log did not take stays in the database as `pending`. WordPress cron appends pending receipts each hour: 50 in one run (filter `agent_custody_door_flush_batch`), the receipts of allowed submissions first, then the oldest first.
86
+
87
+ **When refused submissions flood the site.** A refused submission costs its sender nothing, so the plugin puts a bound on what it costs the site. It makes no request to the log, so refused submissions use at most 50 appends of the log's quota in an hour, and they cannot use up the quota that allowed submissions need. When 500 such receipts are `pending` (filter `agent_custody_door_max_pending`), the door still refuses each submission, and it signs no receipt for it until the flush makes room. Those refusals have no evidence.
88
+
89
+ **When the log has a new key.** The plugin pins the log's keys when it connects, and it refuses an answer that another key signed. To read the keys again, empty the log URL, save, enter the URL and the token, and save.
90
+
91
+ **When the door locks you out.** A wrong challenge key or a log that is down also stops your own login under Humans or Strict. Put `define( 'AGENT_CUSTODY_DOOR_OFF', true );` in `wp-config.php`. The plugin then decides nothing. Correct the settings and remove the line.
92
+
93
+ ## Verify a receipt
94
+
95
+ The settings page lists the last 20 decisions. Each receipt id is a link to its bundle. The page also shows the door's public key: save it as `door.pub`.
96
+
97
+ ```bash
98
+ npx agent-custody verify RECEIPT.json --issuer-key door.pub --log-url https://log.agent-custody.dev/t/YOUR-TENANT/
99
+ ```
100
+
101
+ ## What a receipt records
102
+
103
+ - `request.args`: the method, the path, and the `User-Agent`, `Content-Type`, `Accept`, and `Host` headers. No query, no body, and no digest of the body.
104
+ - `facts.arrival`: as above. The address is `REMOTE_ADDR`. Behind a proxy or a CDN it is the proxy's address.
105
+ - `facts.wordpress`: `{ "loggedIn": true | false }`. It does not name the user.
106
+ - `policy`: the decision, the rules that permitted it, and the digest of the preset's policy text. In Watch, `enforced` is `false`.
107
+ - `execution`: `denied`, `withheld`, or `executed` / `failed` with the HTTP status that WordPress answered.
108
+
109
+ The receipts hold the address and the `User-Agent` of each arrival. They are in the site's database, in the table `wp_agent_custody_receipts`. The receipts that are in the log have two bounds. Such a receipt is deleted after 90 days (filter `agent_custody_door_retention_days`), and the hourly run keeps the newest 10,000 of them (filter `agent_custody_door_max_receipts`). A receipt that is not in the log yet is never deleted: the database has the only evidence of it. The receipt records at most 1,024 characters of the path and of each header. The log has only the hash of a receipt, so download a receipt that you must keep before it is deleted. The plugin keeps its key and its receipts when it is deactivated or deleted: they are the evidence.
110
+
111
+ ## What it does not do
112
+
113
+ - **Admit an agent.** The plugin checks no grant, no Web Bot Auth signature, and no registry passport. An arrival that presents one is `claimed`, never `verified`, and the presets admit it only if it passes the challenge. A site that must admit registered agents runs the Node door in front of WordPress ([the door](door.md)).
114
+ - **Run your own Cedar policy.** The three presets are the policies.
115
+ - **Record the rate, behaviour, or fingerprint signals** of the Node door.
116
+ - **Protect a path it does not see.** XML-RPC (`xmlrpc.php`) signs in, makes comments, and takes pingbacks without the forms, and application passwords sign in without the login form. Put `/xmlrpc.php` in the path list to refuse them. A plugin that moves the login form to another address, or that reads a form before the WordPress `init` action, is not seen.
117
+ - **Put a bound on the challenge checks.** Each submission with a token is one request to the provider, and the visitor waits for it, 5 seconds at most. The Node door has a bound on the checks in flight; the plugin has none.
118
+ - **Give one token to two requests.** A provider accepts a token once. A form of another plugin that sends twice (a validation error, then a second try) needs a new token for the second try, and the widget makes one only when the page resets it.
119
+ - **Sign a receipt for each refusal in a flood.** See "When refused submissions flood the site". Each refused submission is still one request to the challenge provider when it has a token, and one database row until the queue is full.
120
+ - **Protect a post password.** The door does not decide `wp-login.php?action=postpass`.
121
+ - **Work across a multisite network.** Activate it on each site.
122
+
123
+ ## What was checked, and how
124
+
125
+ - `test/door-wordpress.test.ts` runs the plugin's door class with the PHP command line: canonical JSON and digests equal to `crypto.ts`; the key id equal to the verifier's; each preset against Cedar for each challenge outcome and each route, signed in and not; an allowed comment with its authorization and a refused one, each through a real log and through `verifyBundle` with no failed check; nine log answers that must be refused; the challenge outcomes; the routes, with the spellings of a path that must match. It makes no network request. A machine without `php` skips it.
126
+ - `deploy/door/wordpress/smoke.sh` runs a stock WordPress container with MariaDB, Contact Form 7, and a hash-only log. It installs the plugin from its zip, connects it through the settings form, and checks that the comment form, the login form, and the contact page show the widget; that a comment, a login, and a contact form without a token get 403 and pass with a token (Turnstile's public test keys); that a login with an action that WordPress does not know gets 403; that a comment through the REST API without a token gets 403; that three other ways to the contact form (a second spelling of the path, `rest_route` in the query, a `GET` with `_method=POST`) get 403; that a login from a signed-in user without a token gets 403; that a login in Watch goes on and its receipt waits; that a refused submission makes no request to the log; that a comment gets 503 while the log is down; that a refused comment gets no receipt while the queue is full; and that all fourteen receipts are in the log and verify with `agent-custody verify`. The `gateway-image` workflow runs it on each pull request that touches `deploy/door`. Last run on WordPress 7.1.5 with PHP 8.3.
127
+ - By hand, in a browser, on the smoke test's site: the Turnstile widget (test keys) shows in the comment form and in the Contact Form 7 form and makes a token, and a comment and a contact form that are sent from the page pass the door.
128
+ - Not checked: the hosted log at `log.agent-custody.dev` (the smoke test's log is the same server in one-tenant mode over plain HTTP), hCaptcha against its real service, a widget with real keys, the registration form and the lost-password form on a site, and WordPress on PHP 7.4 (the door class passes its tests on PHP 7.4).
@@ -14,7 +14,7 @@ It is the same code as the reverse proxy, the in-process door, and authz mode, w
14
14
  | receipts | the receipts directory | the `RECEIPTS` R2 bucket, same names: `<id>.json`, `<id>.authorization.json`, `salts/<id>.json`, `outbox/<id>.json` |
15
15
  | log | `logFile` or `log.url` | `LOG_URL`, its keys pinned in `LOG_KEYS`, token in the `LOG_TOKEN` secret |
16
16
  | receipts whose log append failed | the outbox, flushed every 30 seconds | the bucket's outbox, flushed by a cron trigger every minute |
17
- | trusted principal keys, revoked grants | files, re-read | the `TRUSTED_PRINCIPAL_KEYS` and `REVOKED_GRANTS` variables; a change is a deploy |
17
+ | trusted principal keys, trusted registry keys, revoked grants, admission lists | files, re-read | the `TRUSTED_PRINCIPAL_KEYS`, `TRUSTED_REGISTRY_KEYS`, `REVOKED_GRANTS`, and `ADMISSION_LISTS` variables; a change is a deploy |
18
18
  | the arrival's address | the socket, or `X-Forwarded-For` with `trustProxy` | `CF-Connecting-IP`, which Cloudflare sets |
19
19
  | Web Bot Auth nonces | one process's memory | a Durable Object per nonce, which every isolate reaches (the `NONCES` binding) |
20
20
  | arrival rates | one process's memory | one isolate's memory |