@agent-custody/receipts 0.16.11 → 0.16.13

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.
Files changed (54) hide show
  1. package/README.md +23 -5
  2. package/dist/admission.d.ts +62 -0
  3. package/dist/admission.js +101 -0
  4. package/dist/check.js +42 -3
  5. package/dist/cli.js +179 -7
  6. package/dist/config.d.ts +6 -1
  7. package/dist/config.js +21 -2
  8. package/dist/door-app.js +1 -1
  9. package/dist/door-core.d.ts +81 -3
  10. package/dist/door-core.js +113 -13
  11. package/dist/door-error-rates.d.ts +102 -0
  12. package/dist/door-error-rates.js +178 -0
  13. package/dist/door-form.d.ts +7 -2
  14. package/dist/door-form.js +52 -4
  15. package/dist/door-measure.d.ts +153 -0
  16. package/dist/door-measure.js +325 -0
  17. package/dist/door-signals.d.ts +414 -0
  18. package/dist/door-signals.js +555 -0
  19. package/dist/door-test-set.d.ts +43 -0
  20. package/dist/door-test-set.js +117 -0
  21. package/dist/door-worker.d.ts +20 -1
  22. package/dist/door-worker.js +30 -2
  23. package/dist/door.js +18 -2
  24. package/dist/erc8004-link.d.ts +24 -0
  25. package/dist/erc8004-link.js +11 -0
  26. package/dist/erc8004.d.ts +26 -0
  27. package/dist/erc8004.js +208 -0
  28. package/dist/index.d.ts +17 -3
  29. package/dist/index.js +9 -2
  30. package/dist/lock.d.ts +5 -0
  31. package/dist/lock.js +1 -1
  32. package/dist/log-store.d.ts +3 -1
  33. package/dist/log-store.js +2 -2
  34. package/dist/passport.d.ts +53 -0
  35. package/dist/passport.js +87 -0
  36. package/dist/portal.d.ts +14 -0
  37. package/dist/portal.js +102 -0
  38. package/dist/registry.d.ts +145 -0
  39. package/dist/registry.js +294 -0
  40. package/dist/web-bot-auth.d.ts +9 -3
  41. package/dist/web-bot-auth.js +31 -4
  42. package/docs/admission-lists.md +89 -0
  43. package/docs/agent-registry.md +173 -0
  44. package/docs/door-error-rates.md +490 -0
  45. package/docs/door-languages.md +3 -1
  46. package/docs/door-middleware.md +6 -1
  47. package/docs/door-quickstart.md +2 -2
  48. package/docs/door-signals.md +112 -2
  49. package/docs/door-worker.md +14 -1
  50. package/docs/door.md +37 -6
  51. package/docs/github-action.md +2 -2
  52. package/docs/tutorials.md +7 -0
  53. package/docs/usage.md +1 -1
  54. package/package.json +2 -1
@@ -34,6 +34,70 @@ Three labels run through the table:
34
34
  | `partner.outcome` | checked, against the engine's key | Only when `partner` is configured and the route is in `partner.routes`. `verified`: the partner engine answered with a verdict whose signature verified under `partner.keyFile` and binds this receipt and route; the verdict is then the `partner` fact (below). `rejected`: the engine answered, and it was not a verdict signed for this arrival: a signature by another key, one for another receipt or route, a verdict of another engine, a malformed verdict, or an envelope carrying more than the attestation (`error` says which). `unavailable`: no answer within `timeoutMs`, an error status, a redirect, or `maxInFlight` questions already waiting | Anything about the arrival when it is not `verified`. Under `onFailure: "deny"` (the default) an arrival without a verified verdict is refused with 503 whatever the policy says; under `"absent"` the policy decides without the `partner` fact |
35
35
  | `method`, `path`, `route` | observed | What arrived, the path percent-decoded once, and the route it fell under | |
36
36
 
37
+ ## The behaviour and fingerprint signals
38
+
39
+ The door adds two fields to the arrival fact when its config has a `behaviour` object: `fingerprint` (what the request and its connection look like) and `behaviour` (how the source acts over time). Without `behaviour` in the config, the arrival fact has neither field, and the door reads no TLS header and no form report. The config is in [the door](door.md#behaviour-and-fingerprint-signals).
40
+
41
+ Nine of the values are flags: booleans that mark an arrival. A flag is not a verdict. The door never refuses an arrival because of a signal. Only your policy reads the signals, and the receipt records each one that the policy read.
42
+
43
+ Each flag is wrong for some people and for some programs. The method that measures how often, and the measured rates, are in [door error rates](door-error-rates.md). `agent-custody door measure` replays a labelled set through the same signal functions, and `agent-custody door labels` exports a labelled set from the receipts of your own door. Measure a flag on your own traffic before a rule reads it.
44
+
45
+ The flags:
46
+
47
+ | signal | label | what it means | what it does not mean |
48
+ | --- | --- | --- | --- |
49
+ | `fingerprint.headers.mismatch` | observed, against a claim | The `User-Agent` states a browser, and the request that the door received lacks a header that this browser sends on every request. The rule always reads `accept-language`. When the door knows that the client used https, the rule also reads `sec-fetch-site`, `sec-fetch-mode`, and `sec-fetch-dest` (Chromium from 80, Firefox from 90, Safari from 17) and `sec-ch-ua` (Chromium from 100; not an Android WebView, a WebView browser with `Version/` before `Chrome/`, Electron, a browser that says `like Chrome/`, or an application that names itself before `Chrome/`). On a POST, PUT, PATCH, or DELETE, on any scheme, the rule also reads `origin` (the same versions as `sec-fetch-*`); a browser sends it on every write, with the value `null` when it hides the origin. An OPTIONS request and an upgrade are checked for `accept-language` only. `missing` names the headers | That the client is a program. The flag is true for a person behind a privacy browser, an extension, or a company proxy that removes one of these headers, for a person whose extension changes the `User-Agent`, and for a Chromium browser that sends no client hints. A proxy in front of the door that drops one of these headers makes every browser a mismatch. It does not mean that an arrival without the flag is a browser: a program that sends the headers of a browser has no mismatch, and a program that states its own name is never a mismatch |
50
+ | `fingerprint.headers.hintsMismatch` | observed, against a claim | The arrival sent `sec-ch-ua`, the `User-Agent` states a browser, and the two do not state the same browser: the `User-Agent` states Firefox or Safari, which send no `sec-ch-ua`, or the major version of the `Chromium` brand is not the major version in the `User-Agent`. A Chromium that is given another `User-Agent` keeps its own `sec-ch-ua`. The rule reads values, so it also works in authz mode when the proxy forwards `sec-ch-ua` | That the client is a program. The flag is true for a person whose extension changes the `User-Agent` and not the client hints. It does not mean that an arrival without the flag is a browser: a program that copies the `User-Agent` of the Chromium that it runs has no flag, and a program can set the client hints too. The rule reads no brand name: in the recorded capture, headless Chrome sends the brands of Chrome |
51
+ | `fingerprint.headers.fetchInvalid` | observed | The `sec-fetch-*` headers have a combination that the Fetch Metadata specification rules out: `sec-fetch-user` without `sec-fetch-mode: navigate`, or `sec-fetch-mode: navigate` with a `sec-fetch-dest` that is not `document`, `iframe`, `frame`, `embed`, `object`, or `fencedframe`. The rules come from the specification, not from data | That an arrival without the flag is a browser: a program that copies a full set of these headers from a browser has no flag. `sec-fetch-site: none` on a write is not in the rule, because a browser extension sends it |
52
+ | `fingerprint.tls.mismatch` | observed, against a claim | The `User-Agent` states a browser of a version that offers TLS 1.3 (Chromium from 70, Firefox from 63, Safari from 13), and the JA4 of a TCP ClientHello shows no TLS 1.3 or no ALPN | That the client is a program. A proxy that inspects TLS between the person and the site (a company network, some antivirus products) sends its own ClientHello, so a person behind one can be a mismatch. So can a person whose organisation turns TLS 1.3 off. It does not mean that an arrival without the flag is a browser: the rule reads two properties of the ClientHello, and a program can have both. A QUIC ClientHello is not checked |
53
+ | `fingerprint.tls.knownTool` | observed | The JA4 is in the door's table of fingerprints of known tools, `KNOWN_TOOL_JA4` | That the tool is hostile, or that a tool not in the table is absent. The table holds six fingerprints, recorded from one build each of curl, Python, Go, Node, and Bun; another build of the same tool can have another fingerprint. A person behind a proxy that uses the same TLS library has the same fingerprint |
54
+ | `behaviour.timing.regular` | checked | The source arrived at a steady pace: at least 5 gaps between its remembered arrivals, a median gap of at least 100 ms, and a difference between the longest gap and the shortest gap of at most 10 % of the median | That the source is a program that you do not want. The flag is true for a page that polls or refreshes on a timer in the browser of a person (a dashboard, a status page), and for the monitoring tool or the health check that you run yourself. It does not mean that an arrival without the flag is a person: a program that varies its pace is not regular, and one more source at the same address breaks the pace |
55
+ | `behaviour.navigation.directWrite` | observed | A POST, PUT, PATCH, or DELETE arrived, the source loaded no HTML document through this door in the last 30 minutes, the `Referer` is absent or names another host, the `Origin` is absent or names another host, and the request has no `Sec-Fetch-Site: same-origin` | That the arrival is a program. The flag is true for every API client that loads no page, a verified agent and a webhook included. It is true for a person whose address changed after the page load, who kept the form open for more than 30 minutes, whose page came from a cache in front of the door, or whose page load went to another door process, when the browser also sends no same-origin `Referer`, no same-origin `Origin`, and no `Sec-Fetch-Site: same-origin` (a form page on another host of the site, or a browser that hides the origin on a site that is not https). It does not mean that an arrival without the flag is a person. The `Referer`, the `Origin`, and `Sec-Fetch-Site` are the client's word: a program that sends a GET for the page first, a `Referer` or an `Origin` that names the host, or `Sec-Fetch-Site: same-origin` has no flag. For a program that loads the page first, read `sincePageMs` |
56
+ | `behaviour.form.fast` | a claim | The form report states at least 8 key presses, and a fill time of less than 20 ms for each key press | That a program filled the form. A device or a tool that types for a person is fast too: a barcode scanner, a security key, a text expander, a password manager that types. The form report is the word of the client's script: a program can send a report that is not fast |
57
+ | `behaviour.form.noInput` | a claim | The form report states a submit with no key press and no pointer press | That a program sent the form. The flag is true for a person whose browser or password manager fills the form and submits it, and for an assistive tool that submits without a key press or a click. A program can send a report that states input |
58
+
59
+ The fields beside the flags:
60
+
61
+ | signal | label | what it means | what it does not mean |
62
+ | --- | --- | --- | --- |
63
+ | `fingerprint.headers.client`, `family`, `version` | a claim | What the `User-Agent` states: `browser` (`chromium`, `firefox`, `safari`), `agent` (an AI agent that names itself; see `vendor` and `purpose` below), `tool` (the name of the tool, or `crawler`), `other`, or `unstated`, and the major version of a browser | What the client is. Any client can send any `User-Agent`. A `User-Agent` with a product name that ends in `bot/`, `crawler/`, or `spider/`, or with a `+http` address, is a `tool` with the family `crawler` |
64
+ | `fingerprint.headers.vendor`, `purpose` | a claim | Only for the client `agent`: the vendor (`openai`, `anthropic`, `perplexity`, `google`) and what the vendor says the agent fetches for: `training` (to train a model), `search` (to build a search index), or `user` (one user asked for this page). The table is `AI_AGENTS` in `src/door-signals.ts`; each entry is from the vendor's own page, and the source is beside it. `family` is the product token in lowercase (`gptbot`, `claude-user`) | That the arrival is that agent. Any client can send the name. The door does not check the address against the ranges that a vendor publishes. A signature is the check: [Web Bot Auth](door.md) makes `signature: "verified"`. A token that a vendor documents for another purpose is a `crawler` |
65
+ | `fingerprint.headers.hints` | observed | Only when the arrival sent `sec-ch-ua`: `version`, the major version of the `Chromium` brand, when the header has one. The header itself is not recorded | |
66
+ | `fingerprint.headers.http` | observed, through Cloudflare | In a Worker only: the HTTP version between the client and Cloudflare (`1.1`, `2`, `3`). A number for your policy, not a flag | That a browser on HTTP/1.1 is a program. A proxy that inspects traffic between the person and the site speaks HTTP/1.1 for the person |
67
+ | `fingerprint.network.asn`, `organization` | observed, through Cloudflare | In a Worker only: the number of the autonomous system of the address and the name of its holder, as Cloudflare gives them. A rule can ask for a challenge when the network is a hosting provider | That an arrival from a hosting network is a program. A person behind a VPN, a company gateway, or a private relay comes from such a network. The Node door has no source for this |
68
+ | `fingerprint.seen` | checked | How many arrivals in the last 60 seconds had this fingerprint (the JA4 and the header order), from every source, this one included. A client that changes its address and keeps its TLS stack and header order is still one fingerprint. Absent when the arrival has no JA4 and no header order. The count stops at 1,000 | That the arrivals are one client. Every copy of one browser version has the same fingerprint, so a busy site sees a high count for a current browser. A number for your policy, not a flag. One process's memory: at most 10,000 fingerprints |
69
+ | `fingerprint.headers.order`, `count` | observed | A hash of the lowercase header names in the order that the door received them, and how many there were, without the door's own headers. No header value is in the hash | The identity of a client. Two clients of the same kind have the same order. A proxy in front of the door can reorder, add, or drop headers, and the door records what it received |
70
+ | `fingerprint.tls.ja4` and the fields from it (`protocol`, `version`, `sni`, `ciphers`, `extensions`, `alpn`) | observed, through your proxy or Cloudflare | The JA4 of the ClientHello, as your proxy wrote it in `behaviour.tlsHeader` or as Cloudflare gives it to a Worker. `malformed` is true when a value arrived that is not a JA4; the door then reads nothing from it | The identity of a client: every copy of one browser version has the same JA4. The door does not see the handshake. When the proxy does not overwrite the header, the value is the client's own |
71
+ | `fingerprint.tls.negotiated`, `cipher`, `extensionsSha1`, `helloLength` | observed, through Cloudflare | In a Worker only: the negotiated TLS version and cipher, Cloudflare's hash of the extensions, and the length of the ClientHello | |
72
+ | `behaviour.timing.gaps`, `medianGapMs`, `minGapMs`, `maxGapMs` | checked | How many gaps the door remembers between the arrivals of this source (at most 16), and their median, their shortest, and their longest in milliseconds. A rule can read the shape: a program that sleeps a random time has gaps inside a band, and a person has long pauses. The source is the name of a verified agent, else the address (for IPv6, its /64) | The pace of one person. One address serves many people |
73
+ | `behaviour.navigation.pageLoaded` | observed | The source sent a GET for an HTML document in the last 30 minutes (`Sec-Fetch-Dest: document`, or without that header an `Accept` that names `text/html`) | That a browser showed the page, or that the same person sends this arrival |
74
+ | `behaviour.navigation.sincePageMs` | checked | Only when `pageLoaded` is true: the milliseconds from that page load to this arrival. On a write, it is the time that the source took to read and fill the page | That a short time is a program: a browser that restores a filled form sends fast. One address serves many people, so the page load can be another person's |
75
+ | `behaviour.navigation.subresources` | checked | Only when `pageLoaded` is true: how many GET requests that are not page loads the source sent after that page load and before this arrival, at most 17. A browser loads the scripts, styles, and images of a page; a program that fetches only the HTML has 0 | Anything when the assets do not go through the door: a site that serves them from a CDN or from another host has 0 for every person. A cached page has 0 too. A number for your policy, not a flag |
76
+ | `behaviour.navigation.origin` | observed | As `referer`, for the `Origin` header. `Origin: null`, which a browser sends when it hides the origin, is `cross-origin`. A `Referrer-Policy` does not remove the `Origin` of a write. The `Origin` itself is not recorded | Where the arrival came from. The client writes the `Origin` |
77
+ | `behaviour.navigation.referer` | observed | `same-origin` when the host of the `Referer` is the `Host` of the request (with `trustProxy`, the `X-Forwarded-Host`); a default port, `:443` or `:80`, on one side only does not change the result. Else `cross-origin`, or `absent`. The `Referer` itself is not recorded | Where the arrival came from. The client writes the `Referer` |
78
+ | `behaviour.navigation.site`, `mode`, `dest` | observed | `sec-fetch-site`, `sec-fetch-mode`, and `sec-fetch-dest` as sent, lowercase; `other` for a value that is not a token | That a browser sent them. A program can send the same values |
79
+ | `behaviour.form.report` and its counts (`fillMs`, `keys`, `pointers`, `pasted`, `trusted`, `moves`, `keySpreadMs`, `readyMs`) | a claim | The form protector script counted the events in the form and sent the counts in `X-Agent-Custody-Form`. `moves` is the count of pointer and touch moves over the form: a tool that types through the browser's debugging interface makes none. `keySpreadMs` is the longest gap between two key presses minus the shortest: a tool that types with a fixed delay has a small one. `readyMs` is the time from the start of the script to the first key press, pointer press, click, or paste. `claimed`: the report is well formed. `malformed`: a value arrived that is not exactly a report; the door then reads nothing from it and sets no flag. The script reads no field value and no key | What happened in a browser. Any client can send the header with any counts. The flags catch only a client that runs the script and does not act as a person does |
80
+
81
+ Limits of these signals:
82
+
83
+ - **The history is one process's memory.** The timing and navigation signals read what this door process remembers: at most 10,000 sources, 17 arrival times for each source, and 30 minutes. The history starts empty when the door starts, and two door processes do not share it. In a Worker, each isolate has its own. A client that sends from many new addresses can make the door forget another source early.
84
+ - **One address is one source.** People behind one address share a history: a page load by one of them is a page load for all, and their arrivals share one pace. A program behind the same address as a person gets that person's page load. The door does not add the `User-Agent` to the key: a client that changes its `User-Agent` would then look new on each arrival.
85
+ - **An IPv6 source is its /64.** One device uses many addresses of its /64, so the door keeps one history for the /64. `rate` still counts by the full address. A browser can load the page over IPv6 and send the form over IPv4. The door then sees two sources, and `pageLoaded` is false for that person; a same-origin `Referer`, `Origin`, or `Sec-Fetch-Site` keeps `directWrite` false.
86
+ - **The door must know that the client used https.** A browser sends `sec-fetch-*` and `sec-ch-ua` to an https site only. The door knows https from the URL of a Worker request, or from `X-Forwarded-Proto: https` with `trustProxy`. Without that, `fingerprint.headers.mismatch` reads `accept-language` only.
87
+ - **Authz mode records no header order.** The proxy selects the headers of a check, so `order` and `count` are absent and `fingerprint.headers.mismatch` is always false. The other signals need the proxy to forward `Referer`, `Origin`, `Accept`, `Sec-Fetch-*`, `Sec-CH-UA`, and `X-Agent-Custody-Form`.
88
+ - **A proxy in front of the door changes what the door receives.** It can reorder or drop headers. The order hash is then the proxy's order, and a dropped header is a mismatch for every browser.
89
+ - **The TLS fingerprint comes from your proxy or from Cloudflare.** `behaviour.tlsHeader` needs `trustProxy`, and your proxy must overwrite the header on every request. In a Worker the data comes from `request.cf`, and a config with `behaviour.tlsHeader` is refused. `ja4` needs Cloudflare Bot Management on the zone. Without it, `tls` has the Cloudflare fields only and `tls.mismatch` is always false.
90
+ - **The form report is a claim.** The script runs in the client's browser, and a program can send the header without the script. The door serves the script only when `challenge` is configured.
91
+
92
+ ## Privacy
93
+
94
+ The signals are data about the device and the conduct of a person, so your privacy duties apply to them. The door does not decide whether you may collect them. That assessment is yours.
95
+
96
+ - **The form report runs in the visitor's browser.** With `behaviour` and `challenge` in the config, the form protector script listens for key, pointer, click, paste, and move events on the form. It keeps counts and times only: no field value, no key identity, and no pointer position. It sends them with the form. Reading events on the device of a visitor is in the scope of rules such as Article 5(3) of the ePrivacy Directive (see the EDPB Guidelines 2/2023 on its technical scope). Whether a security purpose covers it on your site is a question for you and your data protection officer.
97
+ - **A receipt with `behaviour` holds a device fingerprint beside the address.** `fingerprint` (the JA4, the header order hash, in a Worker the network) and `remote` are in the same arrival fact. Together they can identify a device, so treat such a receipt as personal data.
98
+ - **Facts are in clear by default.** The door's default capture rule keeps the arrival fact in clear. A `capture` rule for a route with `"facts": { "mode": "digest" }` or `"encrypted"` keeps the arrival fact out of the readable receipt for that route ([what the receipt records](door.md)). The rule withholds the whole fact, and `door error-rates` and `door labels` then skip those receipts.
99
+ - **The labelled export holds no address.** `agent-custody door labels` writes labels and flags only ([door error rates](door-error-rates.md#measure-on-your-own-door)).
100
+
37
101
  ## The partner verdict
38
102
 
39
103
  A second fact, `partner`, is present only when a partner detection engine (Cloudflare Bot Management, HUMAN, DataDome, behind an adapter that holds an Ed25519 key) signed a verdict for this arrival. The policy reads it as `context.facts.partner`; the receipt records it with provenance `attested` and the engine's signature beside it.
@@ -90,6 +154,52 @@ when { context.facts.arrival.class == "verified" };
90
154
 
91
155
  Decide what `unavailable` means for each route before the provider has its first outage: a forbid on `outcome != "passed"` closes the route then, and the receipts show that the provider, not the arrivals, was the reason.
92
156
 
157
+ The behaviour and fingerprint signals are reasons to ask for more, never reasons to decide what the arrival is. Each flag is wrong for some people ([door error rates](door-error-rates.md)), so a rule that reads a flag gives the arrival a way through: a challenge for a person, a grant for an agent. The next rule asks an arrival for the challenge when a write follows no page load. A verified agent and an arrival that passed the challenge go on:
158
+
159
+ ```cedar
160
+ forbid(principal, action == Action::"refund", resource)
161
+ when {
162
+ context.facts.arrival.behaviour.navigation.directWrite &&
163
+ context.facts.arrival.class != "verified" &&
164
+ context.facts.arrival.challenge.outcome != "passed"
165
+ };
166
+ ```
167
+
168
+ The door answers a refused arrival with 403, the rule's id, and how to pass the challenge. This rule needs `challenge` in the config.
169
+
170
+ `fingerprint.tls` and `behaviour.form` are present only on some arrivals: `tls` when a TLS fingerprint arrived, `form` when the arrival sent a form report. Test for each with `has` before a rule reads it. A rule that reads an absent field is an error, and the door denies an arrival when a rule errors. So a rule without the test refuses every arrival that has no TLS fingerprint or no form report:
171
+
172
+ ```cedar
173
+ forbid(principal, action, resource)
174
+ when {
175
+ (context.facts.arrival.fingerprint.headers.mismatch ||
176
+ (context.facts.arrival.fingerprint has tls && context.facts.arrival.fingerprint.tls.mismatch)) &&
177
+ context.facts.arrival.class != "verified" &&
178
+ context.facts.arrival.challenge.outcome != "passed"
179
+ };
180
+
181
+ forbid(principal, action == Action::"contact", resource)
182
+ when {
183
+ context.facts.arrival.behaviour has form &&
184
+ (context.facts.arrival.behaviour.form.fast || context.facts.arrival.behaviour.form.noInput) &&
185
+ context.facts.arrival.challenge.outcome != "passed"
186
+ };
187
+ ```
188
+
189
+ An arrival with no form report passes the second rule. The report is a claim, so do not write a permit that depends on a report that looks like a person: a program can send one.
190
+
191
+ A steady pace on an API route is a reason to ask the program for a grant. A verified agent is counted by its name, and this rule lets it through:
192
+
193
+ ```cedar
194
+ forbid(principal, action == Action::"api", resource)
195
+ when {
196
+ context.facts.arrival.behaviour.timing.regular &&
197
+ context.facts.arrival.class != "verified"
198
+ };
199
+ ```
200
+
201
+ `fingerprint` and `behaviour` exist only when the config has `behaviour`. A policy that must also work on a door without it tests `context.facts.arrival has behaviour` first. Use observe mode to see what a new rule refuses before you enforce it: the receipts record each flag and each decision. Tutorial: [58-door-behaviour-signals.ts](../examples/58-door-behaviour-signals.ts).
202
+
93
203
  A partner verdict is read through the `partner` fact, which exists only when the engine's signature verified. Test for it before reading it, so a missing verdict denies rather than errors:
94
204
 
95
205
  ```cedar
@@ -99,6 +209,6 @@ when { context.facts has partner && context.facts.partner.verdict == "human" };
99
209
 
100
210
  With `onFailure: "absent"`, the arrival still reaches this rule when the engine is down or its signature is bad, and the rule denies it, because the fact is not there. A rule that does not mention `partner` admits it whatever the engine said, so set `partner.routes` to the routes whose rules read it, or keep the default `onFailure: "deny"`, which refuses the arrival before the policy's answer counts. No setting lets an engine outage become an allow on a route whose rule needs the verdict.
101
211
 
102
- ## What is not a signal yet
212
+ ## What no signal says
103
213
 
104
- Nothing in the arrival fact says whether an arrival that presents nothing is a program. A Web Bot Auth signature identifies an agent that chooses to sign; it says nothing about the ones that do not. A partner engine's verdict is that engine's judgement, signed, and carries the engine's own error rate. The door's own behavioural and fingerprint signals are not built; when they are, each will arrive with a measured error rate beside it, and this page will say what it means. Until then a policy has the grant, the signature, the claims, the address, and the pace, and the receipt records which of them it used.
214
+ Nothing in the arrival fact says whether an arrival that presents nothing is a program or a person. A Web Bot Auth signature identifies an agent that signs; it says nothing about the agents that do not. A partner engine's verdict is the judgement of that engine, signed, with the error rate of that engine. The behaviour and fingerprint signals of the door mark an arrival that does not look or act as its `User-Agent` states. Each flag is wrong for some people and misses some programs, and [door error rates](door-error-rates.md) gives the method and the measured rates. There is no `human` class and no `bot` class. A policy has the grant, the signature, the challenge, the claims, the address, the pace, and the flags, and the receipt records which of them the policy read.
@@ -14,10 +14,12 @@ 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 |
21
+ | the history behind the timing and navigation signals | one process's memory | one isolate's memory |
22
+ | the TLS fingerprint | the header that `behaviour.tlsHeader` names, set by your proxy | `request.cf`, which Cloudflare sets; `behaviour.tlsHeader` is refused |
21
23
 
22
24
  ## What reaches the policy
23
25
 
@@ -25,6 +27,16 @@ Everything the Node door gives it: the arrival fact, the request's arguments, an
25
27
 
26
28
  Where the zone has Cloudflare Bot Management, its score and verified-bot flag enter as a fact named `cloudflare`, labelled `observed`. They reach the policy as `context.facts.cloudflare.score` and `context.facts.cloudflare.verifiedBot`. Cloudflare does not sign them, unlike a partner engine's verdict, which enters `attested`. The fact is read only when `request.cf.botManagement` carries an integer score and a boolean flag, and is never required. A policy that reads it should test for it first: `context.facts has cloudflare && context.facts.cloudflare.score < 30`.
27
29
 
30
+ With `behaviour` in `DOOR_CONFIG` (an empty object is sufficient), the arrival fact has the door's [behaviour and fingerprint signals](door.md#behaviour-and-fingerprint-signals). In a Worker they differ from the Node door in four ways:
31
+
32
+ - `request.cf` also gives the HTTP version (`fingerprint.headers.http`) and the network of the address (`fingerprint.network.asn` and `organization`) on every zone. The Node door has neither.
33
+ - The TLS fingerprint comes from `request.cf`, never from a header. A config with `behaviour.tlsHeader` answers 500 with the reason and relays nothing. `fingerprint.tls` has `negotiated`, `cipher`, `extensionsSha1`, and `helloLength` from the fields that every zone gets. It has `ja4`, and the fields the door reads from it, only where the zone has Bot Management. Without a JA4, `fingerprint.tls.mismatch` is always false.
34
+ - The Worker cannot see the order of the headers, so `fingerprint.headers.order` is absent. `count` leaves out Cloudflare's own `cf-*` and `cdn-loop` headers.
35
+ - The Worker knows from the request URL whether the client used https. For an https request, `fingerprint.headers.mismatch` also reads `sec-fetch-*` and `sec-ch-ua`.
36
+ - The history behind the timing and navigation signals is one isolate's memory.
37
+
38
+ The signals are not verdicts: [door signals](door-signals.md#the-behaviour-and-fingerprint-signals) says what each flag does and does not mean, and [door error rates](door-error-rates.md) gives the method and the measured rates.
39
+
28
40
  ## When R2 or the log is unavailable
29
41
 
30
42
  The rules are the door's own. A request that can change something (any method but `GET`, `HEAD`, and `OPTIONS`, and every route in `precommit`) reaches the origin only after its authorization is committed. That means appended to the log and stored in the bucket. If either fails, the request is answered 503 and not relayed.
@@ -42,6 +54,7 @@ There is no lock between isolates. Two flushes at once can each append the same
42
54
  - **What the Node door does that the Worker does not:** authz mode for nginx and Envoy, a partner engine, OpenTelemetry and Splunk export, a local receipts directory, a local log file, `trustProxy`, and reloading the policy or the revocation list without a deploy.
43
55
  - **Each Web Bot Auth signature costs a Durable Object request.** See [Web Bot Auth nonces](#web-bot-auth-nonces): one claim per verified signature that carries a nonce, and a wait of up to 3 seconds when the object is slow.
44
56
  - **Arrival rates live in one isolate too.** A pace rule sees what one isolate counted.
57
+ - **The history behind the timing and navigation signals lives in one isolate too.** A page load that one isolate saw is unknown to another isolate, so a form post that follows it can be `behaviour.navigation.directWrite` there when it carries no same-origin `Referer`. `behaviour.timing` reads only the arrivals that one isolate saw.
45
58
 
46
59
  ## Web Bot Auth nonces
47
60
 
package/docs/door.md CHANGED
@@ -39,7 +39,7 @@ To run it as a service, the gateway image has a `door` mode (`docker run ... ghc
39
39
 
40
40
  Every field of the config, with its type and default, is in [the door reference](../../../site/reference/door.md#config).
41
41
 
42
- `agent-custody check --config door.json` reads a door config the way the door would: unknown keys, the key, the principal keys, the policy (including a permit that names an agent without requiring a verified arrival, see below), the routes, what is precommitted, the challenge provider or its absence, the partner engine and its key, the revocation file, the origin's scheme, every credential variable the door reads at startup (origin headers, the log, Splunk, OTel, the capture key, the challenge secret), and the paths. It exits 1 on an error.
42
+ `agent-custody check --config door.json` reads a door config the way the door would: unknown keys, the key, the principal keys, the policy (including a permit that names an agent without requiring a verified arrival, see below), the routes, what is precommitted, the challenge provider or its absence, the partner engine and its key, the `behaviour` signals (with a warning that the proxy must overwrite `behaviour.tlsHeader`), the revocation file, the trusted registry keys (an error for one that does not load, or for `trustedRegistryKeys` without `webBotAuth`), the admission lists file (an error for one that cannot be read or is not valid), the origin's scheme, every credential variable the door reads at startup (origin headers, the log, Splunk, OTel, the capture key, the challenge secret), and the paths. It exits 1 on an error.
43
43
 
44
44
  ## What the door knows about an arrival
45
45
 
@@ -47,19 +47,23 @@ The door records one fact for every arrival, `arrival`, observed by the door its
47
47
 
48
48
  | field | values | meaning |
49
49
  | --- | --- | --- |
50
- | `class` | `verified`, `claimed`, `unknown` | `verified`: a grant signed by a trusted principal, inside its window, naming this route among its scopes; or, with no grant, a [Web Bot Auth signature](#web-bot-auth-signatures) that checked against the key its agent's directory publishes. `claimed`: something was asserted that the door could not accept: a grant from a stranger, an expired one, a revoked one, one for other routes, one presented under another agent's signature, a declared agent name, or a signature that did not check or was not checked. `unknown`: nothing was presented |
50
+ | `class` | `verified`, `claimed`, `unknown` | `verified`: a grant signed by a trusted principal, inside its window, naming this route among its scopes; or, with no grant, a [Web Bot Auth signature](#web-bot-auth-signatures) that checked against the key its agent's directory publishes, or a [registry passport](#a-registry-passport) under a signature by the did:key it names. `claimed`: something was asserted that the door could not accept: a grant from a stranger, an expired one, a revoked one, one for other routes, one presented under another agent's signature, a declared agent name, or a signature that did not check or was not checked. `unknown`: nothing was presented |
51
51
  | `subject` | string | the agent named in a verified grant; else the signature agent of a verified signature (its https origin); else the declared name or the agent a rejected grant named; else `unknown`. Only a verified subject reaches the Cedar `principal` |
52
52
  | `grant` | `verified`, `out-of-scope`, `invalid`, `revoked`, `wrong-sender`, `absent` | what became of the grant header, with `grantError` when it was not accepted. `revoked`: the grant verified, and it or a grant above it in its chain is in `revokedGrants` (see [revoking a grant](#revoking-a-grant)). `wrong-sender`: the grant verified, and the request is signed by a signature agent, or by a did:key, that the grant does not name |
53
53
  | `signature` | `verified`, `invalid`, `unavailable`, `unchecked`, `absent` | what became of an RFC 9421 signature tagged `web-bot-auth`, with `signatureError` when it was not verified. `unchecked`: a `Signature-Input` arrived and the config has no `webBotAuth`, so it is a claim. See [Web Bot Auth signatures](#web-bot-auth-signatures) |
54
54
  | `signatureAgent`, `signatureKeyid` | strings | the `Signature-Agent` origin and the keyid the signature named. For a signature by a did:key's key, both are the did:key. Checked only when `signature` is `verified` |
55
55
  | `declared` | string | the `x-agent-custody-agent` header, when sent. A claim |
56
+ | `passport` | `{ outcome, error?, registry?, registryKeyid?, agentId?, agent?, name?, owner?, capabilities?, erc8004?, expiresAt?, digest?, envelope? }` | only when the arrival sent `x-agent-custody-passport`. `verified`: a key in `trustedRegistryKeys` signed it, it is in its window, and the request is signed by the did:key it names, with a signature that covers `@method`, `@path`, `@query`, the passport header, and on a write a `Content-Digest` that matches the body. `unbound`: it verified and the request is signed by its key, without that coverage. `wrong-sender`: it verified, and the request is not signed by that key. `invalid`: it did not verify. `unchecked`: the door trusts no registry key. Only a `verified` passport puts the registry's entry (`agentId`, `name`, `owner`, `capabilities`, `erc8004` when the registry linked an ERC-8004 identity, `expiresAt`, `digest`) and the passport itself (`envelope`) in the fact; another outcome records at most `registry` and `agent`. See [a registry passport](#a-registry-passport) |
57
+ | `admission` | `{ lists, digest }` | only when the config has `admissionLists`. The names of the site's [admission lists](admission-lists.md) the arrival's agent is on, sorted (empty when none), and the sha256 of the lists file in force. Only a `verified` arrival is on a list: by its subject, or by the registry entry or ERC-8004 identity of its `verified` passport |
56
58
  | `remote` | string | the arrival's address |
57
59
  | `challenge` | `{ provider, outcome, error? }` | only when `challenge` is configured. `passed`: the provider confirmed the token the arrival sent. `failed`: the provider refused the token (`invalid-input-response`, `timeout-or-duplicate`, `expired-input-response`, `already-seen-response`, `missing-input-response`, with the codes in `error`), it confirmed a token issued on another hostname or for another action, or the token was longer than 4096 characters, which is refused without calling the provider. `unavailable`: the provider did not answer in time, answered a non-200, a redirect, or something that is not JSON, answered a code that is its own or the operator's fault (`internal-error`, `bad-request`, `missing-input-secret`, `invalid-input-secret`, `sitekey-secret-mismatch`, `invalid-sitekey`, `missing-sitekey`, `invalid-remoteip`: a rotated secret gives every person one of these), or `maxInFlight` checks were already waiting. `absent`: no token. A passed challenge leaves `class` as it was: it says a provider's test was passed in front of this arrival, not who the arrival is |
58
60
  | `partner` | `{ engine, outcome, error? }` | only when `partner` is configured and the route is in `partner.routes`. `verified`: the engine's verdict was signed for this arrival under `partner.keyFile`, and is the `partner` fact. `rejected`: the engine answered with anything else. `unavailable`: it did not answer in time or at all. See [a partner engine's verdict](#a-partner-engines-verdict) |
59
61
  | `rate` | `{ by, burst, minute }` | arrivals from the same source in the last 10 and 60 seconds, this one included, whatever was decided about them, counted by this door process alone. `by` is `agent` for a verified arrival (counted by the agent's name across addresses) or `remote` (by address). A pace, not a verdict |
62
+ | `fingerprint` | `{ headers, tls? }` | only when `behaviour` is configured. What the request and its connection look like: what the `User-Agent` states, a hash of the header order, and the TLS fingerprint when the door has one. See [behaviour and fingerprint signals](#behaviour-and-fingerprint-signals) |
63
+ | `behaviour` | `{ timing, navigation, form? }` | only when `behaviour` is configured. How the source acts over time: its pace, whether a page load came before a write, and the form report when the arrival sent one. Signals, not a verdict |
60
64
  | `method`, `path`, `route` | strings | what arrived, and the route it fell under |
61
65
 
62
- [Door signals](door-signals.md) says, for each field, what it establishes and what it does not, and how a policy should read it.
66
+ [Door signals](door-signals.md) says, for each field, what it establishes and what it does not, and how a policy should read it. [Door error rates](door-error-rates.md) measures how often `class` is wrong for each kind of arrival, with the method, and scores your own receipts against your labels with `agent-custody door error-rates`.
63
67
 
64
68
  There is no `human` class. The door cannot tell a person from a program that presents nothing, and it does not pretend to. With `challenge` configured, a policy can require a passed challenge on a route instead; without it, a policy that lets `unknown` through on a route is letting everything through on that route, and should say so.
65
69
 
@@ -71,6 +75,8 @@ There is no `human` class. The door cannot tell a person from a program that pre
71
75
 
72
76
  **A did:key grant under a signature by its own key is bound to its sender.** <a id="a-did-key-signature"></a>With `webBotAuth` configured, the agent signs the request as for [Web Bot Auth](#web-bot-auth-signatures) (RFC 9421, Ed25519, `tag="web-bot-auth"`, `@authority` covered, `created`, `expires`, and a nonce), and sets `keyid` to its did:key. It sends no `Signature-Agent`, and the door fetches no directory, because the did:key carries the key. The door applies the same checks of the window, the authority, the covered components, and the nonce, and verifies the signature with the key that the did:key names. When the grant verifies and names that did:key, the arrival is `verified` with `signature: "verified"`, and `signatureAgent` and `signatureKeyid` are the did:key. The policy condition for a bound grant, `context.facts.arrival.grant == "verified" && context.facts.arrival.signature == "verified"`, holds for it. A did:key grant under a signature by another did:key's key, or under a Web Bot Auth signature from an https origin, is `wrong-sender`, and the arrival is `claimed`. Anyone can make a key and its did:key, so a did:key signature counts only with a verified grant that names it. With no grant, with a grant that is not verified, or with a grant for another agent, the door records `signature: "invalid"` and the reason in `signatureError`, and the arrival is never `verified` by that signature. `agents` does not list a did:key: the grant of a trusted principal is what admits it. The door keeps the nonce of a did:key signature only when a trusted principal signed the request's grant for that did:key, so signatures by keys that no principal granted cannot fill the nonce store. A door without `webBotAuth` records the signature as `unchecked`, and the grant stays bearer-grade.
73
77
 
78
+ **A registry passport.** <a id="a-registry-passport"></a>An agent registered in an [agent registry](agent-registry.md) holds a passport: a statement, signed by the registry, of the agent's did:key, its owner, a contact, and its capabilities, valid for a day by default. List the registry's key in `trustedRegistryKeys` (the key document is at the registry's `/.well-known/agent-custody-registry.json`) and configure `webBotAuth` (its `agents` may be empty). The agent sends the passport as base64url JSON in `X-Agent-Custody-Passport` and signs the request with its did:key, as [above](#a-did-key-signature), covering `@method`, `@path`, `@query`, the passport header, and on a write `content-digest` ([the agent registry](agent-registry.md#admit-registered-agents-at-a-door) has the full list). With no grant, that arrival is `verified`, its `subject` is the did:key, and `arrival.passport` carries the registry's entry, so a policy can read `context.facts.arrival.passport.capabilities` or `.owner` (test `context.facts.arrival has passport` and `context.facts.arrival.passport.outcome == "verified"` first). The door needs no setup per agent and asks the registry nothing at request time. A passport is public, so on its own it is worth nothing: under another key's signature it is `wrong-sender`, and with no signature it is a claim, and the arrival is `claimed`. A request that presents a grant is judged by its grant; its passport is only recorded. The receipt names the agent as `observed`, as for any signature: a reader can check the recorded passport again under the registry's key, but not the request's signature. Revoking an agent in the registry stops new passports; the one the agent holds works until it expires, so `passportSeconds` on the registry is how long a revocation can take to reach the door.
79
+
74
80
  **Revoking a grant.** <a id="revoking-a-grant"></a>With `revokedGrants` in the config, a grant can be withdrawn before it expires: the file is the gateway's, a JSON array of grant digests, and `agent-custody revoke --config door.json --grant grant.json` appends one. The door re-reads the file when it changes and checks every grant against it after the signature and before the window and the scope, so a running door classifies the next arrival that carries the grant as `claimed` with `grant: "revoked"`, and the Cedar principal is not the agent. Revoking a grant revokes every grant delegated from it (`grantError` says "a grant above it in its chain has been revoked"). A file that is there and cannot be read stops the door from starting; one that becomes unreadable while it runs makes every grant `revoked` until it can be read, so a broken list never lets a grant through. A missing file is an empty list. Without `revokedGrants`, a grant stands until it expires, and `check` warns when the door trusts principals.
75
81
 
76
82
  <a id="challenging-a-human"></a>**Challenging a human.** The door builds no CAPTCHA. With `challenge` configured, a page in front of a protected route renders the provider's widget (Cloudflare Turnstile or hCaptcha) with `siteKey`, and sends the token the widget produced in the `challenge.header` header of its request. The door posts the token and the secret from `secretEnv` to the provider's `siteverify` endpoint, with a timeout, and records the answer as `challenge.outcome`. It adds the arrival's address as `remoteip` only with `trustProxy`, where that address is the client's; without it the socket's address may be a proxy's, and the provider would refuse a token the client solved. It never follows a redirect, which would resend the secret and the token elsewhere. To hCaptcha it also sends `siteKey` as `sitekey`: an hCaptcha secret belongs to the account, and without it a token solved on the account's easiest widget would pass on the hardest. A Turnstile secret belongs to one widget already. `success` alone does not pass: the token must have been issued on one of `hostnames`, and for `action` when one is set, or a token solved on another site that uses this site key, or for another widget, would count. At most `maxInFlight` checks wait on the provider at once; an arrival past that is `unavailable`. The token is stripped before the request is relayed, and neither the token nor the secret is recorded. A policy admits a person on a form route with
@@ -354,6 +360,28 @@ A site that already pays for bot detection (Cloudflare Bot Management, HUMAN, Da
354
360
 
355
361
  What the verdict means, and what it does not, is in [door signals](door-signals.md#the-partner-verdict). Tutorial: [52-door-partner-verdict.ts](../examples/52-door-partner-verdict.ts).
356
362
 
363
+ ## Behaviour and fingerprint signals
364
+
365
+ The door can add its own signals to the arrival fact: what the request looks like, and how its source acts over time. They are off until the config has a `behaviour` object:
366
+
367
+ ```json
368
+ "trustProxy": true,
369
+ "behaviour": { "tlsHeader": "x-ja4" }
370
+ ```
371
+
372
+ An empty object, `"behaviour": {}`, is sufficient. Without `behaviour`, the arrival fact is unchanged, and the door reads no TLS header and no form report.
373
+
374
+ - **What the door adds.** `arrival.fingerprint` has `headers` (what the `User-Agent` states, a hash of the header names in the order received, their count) and, when the door has a TLS fingerprint, `tls`. `arrival.behaviour` has `timing` (the pace of the source), `navigation` (whether the source loaded a page before it writes), and, when the arrival sent a form report, `form`. Each value is a string, an integer, or a boolean. The exact fields are in [the reference](../../../site/reference/door.md#the-arrival-fact).
375
+ - **The flags.** Nine booleans mark an arrival: `fingerprint.headers.mismatch`, `fingerprint.headers.hintsMismatch`, `fingerprint.headers.fetchInvalid`, `fingerprint.tls.mismatch`, `fingerprint.tls.knownTool`, `behaviour.timing.regular`, `behaviour.navigation.directWrite`, `behaviour.form.fast`, and `behaviour.form.noInput`. [Door signals](door-signals.md#the-behaviour-and-fingerprint-signals) says what each flag establishes and who gets flagged wrongly. [Door error rates](door-error-rates.md) gives the method and the measured rates.
376
+ - **The door refuses nothing because of a signal.** Only your policy reads the signals. A rule tests `context.facts.arrival.fingerprint has tls` and `context.facts.arrival.behaviour has form` before it reads those groups, because a rule that reads an absent group is an error and the door then denies the arrival. Treat a flag as a reason to ask for a challenge or a grant: [reading them in a policy](door-signals.md#reading-them-in-a-policy).
377
+ - **`tlsHeader`.** The door does not see the TLS handshake. Your proxy does. `tlsHeader` names the request header in which the proxy puts the JA4 fingerprint of the client. It needs `trustProxy: true`; without that the config does not load. The proxy must overwrite the header on every request. If the proxy passes the header through, a client can send its own fingerprint. If the proxy appends to the header, the door records the value as malformed. Without `tlsHeader` the arrival fact has no `fingerprint.tls`.
378
+ - **https.** A browser sends `sec-fetch-*` and `sec-ch-ua` to an https site only. The door serves plain HTTP, so it knows that the client used https only from `X-Forwarded-Proto: https` with `trustProxy`. Without that, `fingerprint.headers.mismatch` reads `accept-language` only.
379
+ - **A proxy in front of the door.** The door records the headers that it received. A proxy that reorders headers changes `fingerprint.headers.order`, and a proxy that drops `accept-language`, `sec-fetch-*`, or `sec-ch-ua` makes every browser a mismatch.
380
+ - **The history.** The timing and navigation signals read the history of the source: a verified agent by its name, else the address, as `rate` does. The history is one process's memory: at most 10,000 sources, 17 arrival times for each source, and 30 minutes. It starts empty when the door starts, and two door processes do not share it.
381
+ - **The form report.** With `challenge` and `behaviour` configured, the [form protector](#protecting-a-form-with-one-line) script also counts key presses, pointer presses, clicks, and pastes in each form, and sends the counts in `X-Agent-Custody-Form`. The script reads no field value and no key. The door removes the header before it relays the request. The report is a claim by the script in the client's browser: a program can send any report.
382
+
383
+ `agent-custody door labels` exports a labelled set from the receipts of your own door, and `agent-custody door measure` replays a labelled set through the same signal functions and prints how often each flag is wrong ([door error rates](door-error-rates.md)). Tutorial: [60-door-behaviour-signals.ts](../examples/60-door-behaviour-signals.ts).
384
+
357
385
  ## How an arrival becomes a Cedar request
358
386
 
359
387
  | Cedar slot | value |
@@ -435,6 +463,7 @@ A site that already runs nginx or Envoy need not send its traffic through the do
435
463
  ```
436
464
 
437
465
  - **What the door reads.** The proxy sets `X-Original-Method` (the original request's method) and `X-Original-URI` (its path and query), and `X-Forwarded-For` (the client's address; `trustProxy` is required, and the door takes the last address), and passes the client's headers the door reads: the grant, `X-Agent-Custody-Agent`, `Signature`, `Signature-Input`, `Signature-Agent`, the challenge header, `User-Agent`, `Accept`, `Content-Type`, and the client's `Host`. The check request's own method and path are the proxy's and are ignored; the door decides, and checks a [Web Bot Auth](#web-bot-auth-signatures) signature, on the original method, target, and `Host`; a check without the two `X-Original-*` headers is answered 400 with no receipt.
466
+ - **The behaviour signals.** With `behaviour` in the config, the door reads the signals from the check. The proxy selects the headers of a check, so the door records no header order and no header count, and `fingerprint.headers.mismatch` is always false. For the other signals the proxy must forward `Referer`, `Origin`, `Accept`, `Sec-Fetch-Site`, `Sec-Fetch-Mode`, `Sec-Fetch-Dest`, `Sec-Fetch-User`, `Sec-CH-UA`, `X-Agent-Custody-Form`, and the header that `behaviour.tlsHeader` names. The proxy must set the `tlsHeader` itself and replace any copy from the client. The door relays nothing in authz mode, so the proxy also passes `X-Agent-Custody-Form` to the origin unless you remove it there.
438
467
  - **What it answers.** 200 with `X-Agent-Custody-Receipt` and `X-Agent-Custody-Class`, which the proxy passes to the origin in place of anything the client sent under those names; 403 on a refusal; 503 when the log refused the authorization of a request that can change something; 400 for a path that does not decode cleanly. nginx relays only on a 2xx, refuses on 401 and 403, and answers 500 for anything else; Envoy relays only on 200 and returns anything else to the client. Both stock configs fail closed when the door is down.
439
468
  - **Commit before relay still holds.** Any method but GET, HEAD, and OPTIONS, and any route in `precommit`, is committed to the log before the door answers 200, so the evidence exists before the proxy can relay the request.
440
469
 
@@ -451,11 +480,13 @@ A site that already runs nginx or Envoy need not send its traffic through the do
451
480
  - The proxy sets `X-Original-Method`, `X-Original-URI`, and `X-Forwarded-For` itself, replacing any copy the client sent (nginx `proxy_set_header`, Envoy `headers_to_add` with `use_remote_address: true`). A config that passes the client's copies lets the client choose what the door decides on.
452
481
  - The door decides on the path as it normalises it (percent-decoded once, empty segments merged) and refuses a segment that decodes to a slash or a dot segment; the proxy relays the path as the client sent it. Relay it unchanged (nginx `proxy_pass` with no URI part, no Envoy rewrite) and let the origin normalise as the door does, or a path the origin reads differently is a way around a route.
453
482
  - The stock configs strip `X-Agent-Custody-Grant` and `X-Agent-Custody-Agent` before the origin. `Authorization` reaches the origin unchanged, since the origin may use it: behind a proxy an agent should send its grant in `X-Agent-Custody-Grant`.
454
- - Envoy sends the door only the client headers in `allowed_headers`. A new header the policy reads, such as a challenge header under another name, goes into that list.
483
+ - Envoy sends the door only the client headers in `allowed_headers`. A new header the policy reads, such as a challenge header under another name, goes into that list. For `behaviour`, the stock config has `referer`, `sec-fetch-site`, `sec-fetch-mode`, `sec-fetch-dest`, and `x-agent-custody-form` in that list. It does not have the `behaviour.tlsHeader`: add the header that you named, and make Envoy set it.
455
484
 
456
485
  ## What it does not do yet
457
486
 
458
- - Detect agents in web or API traffic itself. An agent that signs per Web Bot Auth is identified by its signature, and a partner engine's signed verdict can be had; beyond those the only signals are the ones in the arrival fact: `declared` is a claim and `rate` is a pace ([door signals](door-signals.md)).
487
+ - Detect agents in web or API traffic itself. An agent that signs per Web Bot Auth is identified by its signature, and a partner engine's signed verdict can be had; beyond those the only signals are the ones in the arrival fact: `declared` is a claim, `rate` is a pace, and the [behaviour and fingerprint signals](#behaviour-and-fingerprint-signals) are flags that are wrong for some arrivals ([door signals](door-signals.md), [door error rates](door-error-rates.md)). No signal is a verdict.
488
+ - Share the history behind the timing and navigation signals between door processes, or keep it across a restart.
489
+ - Know the TLS fingerprint of every tool. The table behind `fingerprint.tls.knownTool` holds six fingerprints, recorded from one build each of curl, Python, Go, Node, and Bun on one machine. Another build or another tool is not in it, and the flag has no measured rate ([door error rates](door-error-rates.md)).
459
490
  - Authenticate to a partner engine. The question carries no credential: put the adapter that holds the engine's API key and the signing key where only the door reaches it.
460
491
  - Check AP2 mandates.
461
492
  - Check every Web Bot Auth signature: Ed25519 only (no RSA-PSS or ECDSA), the components listed above only, no `Content-Digest`, no response signatures on the directory, and nonces in one process's memory (the Worker keeps them in a Durable Object that every isolate reaches: [the door as a Cloudflare Worker](door-worker.md#web-bot-auth-nonces)). A signature agent must be listed in `agents`; the door does not fetch the directory of an origin it was not told about.
@@ -464,4 +495,4 @@ A site that already runs nginx or Envoy need not send its traffic through the do
464
495
  - Stream a request body: the body is read whole, up to `maxBodyBytes`, so that the policy can read it and the receipt can commit to it.
465
496
  - Relay a response larger than `maxResponseBytes`, or stream one: the body is relayed whole so that its digest can be recorded. A larger one is not held: reading stops at the limit, the client gets 502, and the receipt records that the origin answered.
466
497
 
467
- Tutorials: [40-door.ts](../examples/40-door.ts), the proxy; [48-door-app.ts](../examples/48-door-app.ts), in-process; [49-door-authz.ts](../examples/49-door-authz.ts), behind nginx or Envoy; [examples/languages/door](../examples/languages/door), middleware for Go, Rails, Django, and Spring; [52-door-partner-verdict.ts](../examples/52-door-partner-verdict.ts), a partner engine's signed verdict; [56-door-worker.ts](../examples/56-door-worker.ts), the door as a Cloudflare Worker, in workerd.
498
+ Tutorials: [40-door.ts](../examples/40-door.ts), the proxy; [48-door-app.ts](../examples/48-door-app.ts), in-process; [49-door-authz.ts](../examples/49-door-authz.ts), behind nginx or Envoy; [examples/languages/door](../examples/languages/door), middleware for Go, Rails, Django, and Spring; [52-door-partner-verdict.ts](../examples/52-door-partner-verdict.ts), a partner engine's signed verdict; [56-door-worker.ts](../examples/56-door-worker.ts), the door as a Cloudflare Worker, in workerd; [58-door-error-rates.ts](../examples/58-door-error-rates.ts), the error rates; [60-door-behaviour-signals.ts](../examples/60-door-behaviour-signals.ts), the behaviour and fingerprint signals.
@@ -20,7 +20,7 @@ jobs:
20
20
  runs-on: ubuntu-latest
21
21
  steps:
22
22
  - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
23
- - uses: svayatta/agent-custody@<commit sha of the release> # 0.16.11
23
+ - uses: svayatta/agent-custody@<commit sha of the release> # 0.16.13
24
24
  with:
25
25
  path: .custody/receipts
26
26
  issuer-key: .custody/keys/agent.pub
@@ -37,7 +37,7 @@ Pin the action to the commit of a release, as you pin every other action. A movi
37
37
  | `principal-key` | the public key files of the principals whose grants a gateway receipt carries, one path on each line; SDK and Claude Code hook receipts need none | |
38
38
  | `log-url` | the URL of the log; the action fetches the log key from it (`verify --log-url`) | |
39
39
  | `log-id` | the id that every tree head must name (`verify --log-id`) | |
40
- | `version` | the `@agent-custody/receipts` version that `npx` runs | `0.16.11` |
40
+ | `version` | the `@agent-custody/receipts` version that `npx` runs | `0.16.13` |
41
41
  | `github-token` | a token that can write pull request comments; an empty value writes the job summary only | `github.token` |
42
42
  | `comment-author` | the login of the account that `github-token` posts as; the action edits only a comment from this account | `github-actions[bot]` |
43
43
 
package/docs/tutorials.md CHANGED
@@ -66,6 +66,13 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
66
66
  | 55 | a grant that names its agent by a did:key, checked at the door | [55-did-key-grant.ts](../examples/55-did-key-grant.ts) | an agent's Ed25519 key and its did:key; a principal's grant for the did:key is verified at the door; a garbled did:key, and a grant whose agentKey is another key, are claimed; nothing presented is unknown; every receipt verifies |
67
67
  | 56 | the door as a Cloudflare Worker | [56-door-worker.ts](../examples/56-door-worker.ts) | the Worker built as `wrangler deploy` builds it and run in workerd (Miniflare): the key a secret binding, the policy and config variables, receipts to an R2 bucket and a local log over HTTP; an order with no grant refused before the origin, an order under a grant committed to the log first and relayed; both receipts verified with the Worker's public key and the log's |
68
68
  | 57 | human in the loop: the gateway asks, a person signs from the command line, the agent retries | [57-approval-requests.ts](../examples/57-approval-requests.ts) | a refund that needs approval arrives with none and is refused, leaving a request; `agent-custody approvals list` and `show` give the approver the exact arguments, `approve` signs them with their key; the same call again is forwarded once and its receipt verifies with the approver's key; a third send, and the same refund for one penny more, are each refused and wait for a person again |
69
+ | 58 | published error rates for the door's signals | [58-door-error-rates.ts](../examples/58-door-error-rates.ts) | twelve kinds of arrival built to a known label (a browser, two scripts, two genuine agents, seven impostors) decided by the door core; every receipt verified and each kind scored on its own with a 95% interval: `verified` goes to the genuine agents only, and a script that presents nothing is `unknown` like the browser; an operator's label is its own row, and a receipt edited to say `verified` is skipped and moves nothing |
70
+ | 59 | Demo 1, the refund (API leg): the door and the gateway together | [59-refund-demo.ts](../examples/59-refund-demo.ts) | a shop with the door in front of its refund API and two payment lanes through the gateway; a shopping agent with a passport is paid £25 once, even on retry; £80, and a forged passport, are refused at the door and never reach the shop; an agent with no passport goes to a person, who approves the exact refund with `agent-custody approvals approve`, and is then paid once; an auditor with public keys and a read-only view of Stripe verifies all ten receipts and finds the £10 refund made in Stripe directly; `bun run demo:refund` |
71
+ | 60 | the door's behaviour and fingerprint signals, read by a policy as reasons to ask for a challenge | [60-door-behaviour-signals.ts](../examples/60-door-behaviour-signals.ts) | a door with `behaviour` and a challenge in front of a contact form; a browser's page load and form post carry no flag and pass; a tool's direct post is `directWrite`, and a script that states a browser has four flags, and each is refused with the rule's id and how to pass the challenge; a person whose address changed, and whose form page is on another host of the site, is flagged too, and passes with a challenge token; the site never receives the form report header; every receipt verified, with its flags |
72
+ | 61 | the false-positive rate of each door flag, measured on a labelled set | [61-door-measure.ts](../examples/61-door-measure.ts) | the labelled set recorded from real clients is replayed through the door's signal functions; each flag's false-positive rate and detection rate are printed per session and per arrival with the 95% interval; no real browser is flagged, and the interval is still wide because the set is small |
73
+ | 62 | the agent registry: an organisation registers its agent, receives a passport, and a door that holds only the registry's key admits it | [62-agent-registry.ts](../examples/62-agent-registry.ts) | the portal runs the registry and publishes its key document; a company registers its shopping agent by the agent's own did:key with the capability `refunds`, and gets a passport; a shop's door trusts the registry's key and nothing else; the agent's refund, with its passport and signed by its key, is `verified` and the policy reads the capability; the same passport under another key's signature is `wrong-sender` and refused; after the company revokes the agent the registry issues it no passport; every receipt verified |
74
+ | 63 | linking a registered agent to its ERC-8004 identity, checked on chain by the registry and carried in its passport | [63-agent-registry-erc8004.ts](../examples/63-agent-registry-erc8004.ts) | a stand-in Base node and file host; the registry links the agent to token 7 because its registration file lists the agent's did:key, and records the owner and the block; the passport carries the link; a link to token 8, whose file names another key, is refused |
75
+ | 64 | admission lists: a site finds agents in the registry by capability, lists a partner by its registry entry and blocks another by its key, and its policy reads the lists | [64-admission-lists.ts](../examples/64-admission-lists.ts) | two companies register shopping agents with `refunds`; the shop's search finds both; its door trusts the registry's key and reads `admission.json`; Carted's agent is on `partners` and its refund is allowed; Grabby's agent is verified and on `blocked`, and its refund is refused; each receipt records the lists and their digest, and verifies |
69
76
 
70
77
  ## How policies are defined, in one paragraph
71
78
 
package/docs/usage.md CHANGED
@@ -125,7 +125,7 @@ At startup the gateway fetches the agent's card from `<url>/.well-known/agent-ca
125
125
  "log": { "url": "https://log.example.com/", "tokenEnv": "AGENT_CUSTODY_LOG_TOKEN" }
126
126
  ```
127
127
 
128
- Exactly one of the two. The bearer token comes from the named environment variable, never from the file, and a missing variable fails at startup. Add `"hashOnly": true` for any log run by someone else: the gateway then sends only the leaf hash, sha256 of the receipt envelope with the RFC 6962 prefix, so the log commits to the receipt without ever holding it, and the receipts with their arguments and results stay in `receiptsDir`. The verifier does not change; it hashes the envelope itself. A log that serves several tenants is reached at `<url>/t/<tenant>/`, and each of its tree heads names its log, which a verifier checks with `--log-id`. With a remote log the tree head in each receipt is signed by the log's key, and a verifier must be given that key with `--log-key`. The gateway does not take the log's answer on trust either: the tree head in every append's answer must verify against the log's keys, name the expected log, match the proof's size, and the inclusion proof must place that very leaf under the signed root, all before a pre-committed call is forwarded and before any receipt is handed out; an answer that fails any of it is a refusal. `"keys": ["keys/log.pub"]` pins the log's public keys, `"logId"` the id its heads must carry; without `keys` the log's key document at `/.well-known/agent-custody-log.json` is fetched from the log itself once, on the first append, and pinned. That catches a log that turns dishonest later, not one that is dishonest from the start, so a gateway config with `precommit` and a remote log must list `keys`. When the log rotates its key, add the new public key to `keys`; a gateway that fetched the keys needs a restart. An append that gets no answer within `timeoutMs` (default 10000) counts as unreachable and is retried like a server error, so a log that accepts connections and never answers cannot hold a call forever. If the log does not take a receipt, the gateway keeps the signed receipt in `receipts/outbox/<receiptId>.json` and returns the real outcome of the call to the agent, with the receipt id and `_meta["agent-custody/log-pending"]: true`. The gateway appends the outbox at startup and every 30 seconds, and writes `receipts/<receiptId>.json` when the log takes the receipt. Until then no bundle exists, so no receipt that was never logged is handed out. The table [below](#when-the-log-fails) gives each case. For a tool named in `precommit` the order is reversed, below, and the action never happens. A fact lookup is different: it runs before the policy decides, because the policy decides on it, and only once the intercepted tool is in the grant's scope, so a fact tool must be a read. Naming a fact tool in `precommit` is refused at startup; `"*"` covers the tools the agent calls, not the gateway's own lookups. Every lookup is on the receipt with its arguments. The reference log server is `node src/cli.ts log --file log.jsonl --key keys/log.key --port 8787 --token-env AGENT_CUSTODY_LOG_TOKEN [--log-id <id>] [--tenants tenants.json]`. It serves `POST /append` with `{leaf}` or `{leafHash}` (token required when one is configured), `GET /root?size=N`, `GET /consistency?old=M&new=N`, and `GET /head`; [verification.md](verification.md) says what each proves. `--log-id` writes that id into every tree head. `--tenants` names a JSON file, `{ "acme": { "file": "acme.jsonl", "tokenEnv": "ACME_TOKEN", "logId": "acme-eu" } }`, and each tenant is its own log at `/t/acme/…` with its own token and id; the default log stays at the root paths. With `--hash-only` the server refuses `{leaf}` at append and accepts only `{leafHash}`, so a log run for other people never receives a receipt regardless of the client's configuration; the hosted deployment sets it. With `--db-env DATABASE_URL` the server keeps its logs in Postgres instead of files, and needs the `pg` package beside it: leaves as hashes in one table keyed by tenant, one writer per tenant enforced with an advisory lock so a second instance is safe, tenants and their tokens in tables of their own with tokens stored only as hashes, and rate limits per token (50 appends a second, burst 100, a 64 KB body cap; a refused append answers 429 with `retry-after`, and the gateway's sink retries a few times). Tenants are managed with `log-admin --db-env DATABASE_URL`: `tenant add <id> [--log-id <id>]` (both plain identifiers: letters, digits, `.`, `_`, `-`), `token add <tenant> --label <text>` (the token is printed once), `token revoke <tenant> <hash-prefix>`, `tenant disable <id>`, `tenant plan <id> <free|team|enterprise>`, and `import --file log.jsonl [--tenant default]` to bring an existing file log in as hashes. Every tenant is on a plan, `free` unless moved: free allows ten thousand appends a calendar month, team a million, enterprise has no allowance. An append past the allowance is refused with 429, the numbers, and a `retry-after` that reaches the start of next month; the gateway behind it then withholds pre-committed calls and financial operations, so a tenant out of quota never acts on those without evidence. Any other call is forwarded, and its receipt waits in the outbox ([below](#when-the-log-fails)). The tenant's own `GET /t/<name>/usage` reports the plan and quota beside the month's appends. The tenant portal, `agent-custody portal --db-env DATABASE_URL --secret-env PORTAL_SECRET --public-url <log url> [--checkpoints-url <url>] [--portal-url <url>] [--stripe-key-env NAME --stripe-webhook-env NAME --stripe-price-team <price id>] [--trust-proxy]`, is the self-serve front of the same tables: a team registers with an email, a password (scrypt), and a tenant id and gets the tenant and its first key shown once with the welcome sheet; the dashboard shows appends against the plan, the tree size and root, the latest checkpoint, the log's URLs, keys, and the audit rows; keys are minted and revoked there, recorded as `portal:<email>`; the export command is on the page; and with the three Stripe variables the team plan is bought through Stripe Checkout, the signed webhook moving the plan (`stripe:<event>` in the audit trail) and the customer portal handling cancellation. Sessions are a signed cookie, `SameSite=Strict`, and every write needs a JSON body: one over 64 KB is answered 413, one that is not JSON 400, and any other failure a plain 500 with the detail in the portal's log, never in the answer. Each member has a role (`owner`, `admin`, `reviewer`, `readonly`), an account can turn on TOTP MFA, and the operator can set up single sign-on through the tenant's own OIDC or SAML identity provider with `log-admin sso set`; the [hosted log reference](https://docs.agent-custody.dev/reference/hosted) lists the routes. SAML needs `@node-saml/node-saml` beside the CLI. The compose file runs it as the `portal` service at `PORTAL_HOST`. The root paths serve the tenant `default`, created on first start with `--log-id`, and `--token-env` still works for it. The key that signs tree heads can live in its own process: `agent-custody signer --key keys/log.key --port 8790 --token-env SIGNER_TOKEN` holds it and answers `POST /sign` with the shared secret and `GET /keys` to anyone; the log server then runs with `--signer-url http://signer:8790/ --signer-token-env SIGNER_TOKEN` instead of `--key`, and the process that faces the internet never holds the key. Either way the log serves its keys at `/.well-known/agent-custody-log.json`, current key first and retired keys (`--retired-key old.pub`) after it, so verifiers fetch and pin them with `verify --log-url` and `audit --log-url` rather than receiving a key file from the operator. With `--checkpoint-dir <dir>` the server publishes a signed checkpoint, every `--checkpoint-every` seconds (default 300), for each log whose tree has grown, and every `--checkpoint-heartbeat` seconds (default 21600, six hours) for a log that has not, so a quiet log's latest checkpoint is never more than six hours old and the monitor can tell quiet from stalled, as `<dir>/<tenant>/<treeSize>.json` and `latest.json`, and with a database also as rows; `GET /checkpoints?since=<size>` and `GET /t/<tenant>/checkpoints` list them. Serve the directory read-only from a second host, so the record of what the log signed does not depend on the log's API being up; a verifier who kept an earlier head audits against a later checkpoint with `audit --older <bundle> --newer <checkpoint> --log-url <url>`. With `--admin-token-env ADMIN_TOKEN` (Postgres only) the server also serves the operator's page at `/admin` and its API under `/admin/`: list and create tenants, mint a token that is shown once beside the tenant's welcome sheet, revoke tokens, disable tenants. Everything under `/admin`, the page included, needs the admin token: the browser asks for it (any user name, the token as the password) and an API client sends it as a bearer; a handful of wrong attempts from one address are throttled for a minute. Every change made there or with `log-admin` is recorded: who (the name entered at the browser prompt and the address, `bearer` for an API client, or the user and host for the command line), what (`tenant.add`, `tenant.disable`, `token.add`, `token.revoke`), which tenant, and the detail, never the token itself; the page shows it under Activity, `GET /admin/audit?tenant=&limit=` and `log-admin audit` list it, and a tenant reads their own rows at `GET /t/<name>/audit` with their token. Nothing else is stored by the page. Behind a reverse proxy, start the server with `--trust-proxy` so those per-address limits key on `X-Forwarded-For` instead of on the proxy's own address, and only there, since the header is otherwise the client's to forge. `--public-url` and `--checkpoints-url` fill the sheet in. The witness closes the last gap: `agent-custody witness --key witness.key --log-url <url> --checkpoints-url <url> --out <dir> [--tenant <name>]...` runs on a machine the log's operator does not control, fetches each watched log's latest checkpoint, verifies it against the log's published keys, proves with the log's consistency proof that it extends the last head the witness signed, and countersigns it into `<dir>/<tenant>/<size>.json` and `latest.json`; a checkpoint that does not extend, or a second history at the same size, gets `ALARM.json` instead. Its key document is `<dir>/.well-known/agent-custody-witness.json`. Serve `<dir>` from the witness's own host; verifiers add `--witness-url` (or `--witness-key`) to `audit`, and the newer head must then carry the witness's signature. Two more things an operator needs. `agent-custody log-check --log-url <url> --checkpoints-url <url> [--witness-url <url>] [--tenant <name>]... [--max-lag <seconds>]` is the outside monitor: it verifies the head against the published keys, that the latest checkpoint verifies and keeps up with the head, that the head extends the checkpoint, and, with a witness, that the witness has countersigned, keeps up, and has raised no alarm; it exits 1 on any failure, so cron or a scheduled workflow on a machine that is not the log's turns it into an alert. `GET /health` on the server is the liveness check for a load balancer. And `GET /admin/usage?month=YYYY-MM`, on the admin page and as `/admin/usage.csv`, is the metering: appends per tenant for the month, leaves in total, live tokens, the numbers any invoice rests on. A tenant needs none of that to leave with their evidence: `agent-custody log-export --log-url <url> --tenant <name> --token-env AGENT_CUSTODY_LOG_TOKEN --out <dir>` fetches, with their own token, every leaf hash (`GET /t/<name>/leaves?since=&limit=`, pages of up to ten thousand), the signed head, the published keys, the signed checkpoints, their own usage (`GET /t/<name>/usage?month=`), and the administrative actions on their tenant (`GET /t/<name>/audit`, into `audit.json`), checks that the head and every checkpoint verify against the keys and that the leaves fetched hash to their roots, and writes `log.jsonl` in the format `verify --log` and `audit --log` read, so the export verifies receipts with no server at all. It exits 1 and says what did not add up if anything does not. Both routes answer only to that tenant's token. [deploy/](../../deploy/README.md) runs the server, the signer, Postgres, and the checkpoints host as containers, and [deploy/witness/](../../deploy/witness/) the witness.
128
+ Exactly one of the two. The bearer token comes from the named environment variable, never from the file, and a missing variable fails at startup. Add `"hashOnly": true` for any log run by someone else: the gateway then sends only the leaf hash, sha256 of the receipt envelope with the RFC 6962 prefix, so the log commits to the receipt without ever holding it, and the receipts with their arguments and results stay in `receiptsDir`. The verifier does not change; it hashes the envelope itself. A log that serves several tenants is reached at `<url>/t/<tenant>/`, and each of its tree heads names its log, which a verifier checks with `--log-id`. With a remote log the tree head in each receipt is signed by the log's key, and a verifier must be given that key with `--log-key`. The gateway does not take the log's answer on trust either: the tree head in every append's answer must verify against the log's keys, name the expected log, match the proof's size, and the inclusion proof must place that very leaf under the signed root, all before a pre-committed call is forwarded and before any receipt is handed out; an answer that fails any of it is a refusal. `"keys": ["keys/log.pub"]` pins the log's public keys, `"logId"` the id its heads must carry; without `keys` the log's key document at `/.well-known/agent-custody-log.json` is fetched from the log itself once, on the first append, and pinned. That catches a log that turns dishonest later, not one that is dishonest from the start, so a gateway config with `precommit` and a remote log must list `keys`. When the log rotates its key, add the new public key to `keys`; a gateway that fetched the keys needs a restart. An append that gets no answer within `timeoutMs` (default 10000) counts as unreachable and is retried like a server error, so a log that accepts connections and never answers cannot hold a call forever. If the log does not take a receipt, the gateway keeps the signed receipt in `receipts/outbox/<receiptId>.json` and returns the real outcome of the call to the agent, with the receipt id and `_meta["agent-custody/log-pending"]: true`. The gateway appends the outbox at startup and every 30 seconds, and writes `receipts/<receiptId>.json` when the log takes the receipt. Until then no bundle exists, so no receipt that was never logged is handed out. The table [below](#when-the-log-fails) gives each case. For a tool named in `precommit` the order is reversed, below, and the action never happens. A fact lookup is different: it runs before the policy decides, because the policy decides on it, and only once the intercepted tool is in the grant's scope, so a fact tool must be a read. Naming a fact tool in `precommit` is refused at startup; `"*"` covers the tools the agent calls, not the gateway's own lookups. Every lookup is on the receipt with its arguments. The reference log server is `node src/cli.ts log --file log.jsonl --key keys/log.key --port 8787 --token-env AGENT_CUSTODY_LOG_TOKEN [--log-id <id>] [--tenants tenants.json]`. It serves `POST /append` with `{leaf}` or `{leafHash}` (token required when one is configured), `GET /root?size=N`, `GET /consistency?old=M&new=N`, and `GET /head`; [verification.md](verification.md) says what each proves. `--log-id` writes that id into every tree head. `--tenants` names a JSON file, `{ "acme": { "file": "acme.jsonl", "tokenEnv": "ACME_TOKEN", "logId": "acme-eu" } }`, and each tenant is its own log at `/t/acme/…` with its own token and id; the default log stays at the root paths. With `--hash-only` the server refuses `{leaf}` at append and accepts only `{leafHash}`, so a log run for other people never receives a receipt regardless of the client's configuration; the hosted deployment sets it. With `--db-env DATABASE_URL` the server keeps its logs in Postgres instead of files, and needs the `pg` package beside it: leaves as hashes in one table keyed by tenant, one writer per tenant enforced with an advisory lock so a second instance is safe, tenants and their tokens in tables of their own with tokens stored only as hashes, and rate limits per token (50 appends a second, burst 100, a 64 KB body cap; a refused append answers 429 with `retry-after`, and the gateway's sink retries a few times). Tenants are managed with `log-admin --db-env DATABASE_URL`: `tenant add <id> [--log-id <id>]` (both plain identifiers: letters, digits, `.`, `_`, `-`), `token add <tenant> --label <text>` (the token is printed once), `token revoke <tenant> <hash-prefix>`, `tenant disable <id>`, `tenant plan <id> <free|team|enterprise>`, and `import --file log.jsonl [--tenant default]` to bring an existing file log in as hashes. Every tenant is on a plan, `free` unless moved: free allows ten thousand appends a calendar month, team a million, enterprise has no allowance. An append past the allowance is refused with 429, the numbers, and a `retry-after` that reaches the start of next month; the gateway behind it then withholds pre-committed calls and financial operations, so a tenant out of quota never acts on those without evidence. Any other call is forwarded, and its receipt waits in the outbox ([below](#when-the-log-fails)). The tenant's own `GET /t/<name>/usage` reports the plan and quota beside the month's appends. The tenant portal, `agent-custody portal --db-env DATABASE_URL --secret-env PORTAL_SECRET --public-url <log url> [--checkpoints-url <url>] [--portal-url <url>] [--stripe-key-env NAME --stripe-webhook-env NAME --stripe-price-team <price id>] [--trust-proxy]`, is the self-serve front of the same tables: a team registers with an email, a password (scrypt), and a tenant id and gets the tenant and its first key shown once with the welcome sheet; the dashboard shows appends against the plan, the tree size and root, the latest checkpoint, the log's URLs, keys, and the audit rows; keys are minted and revoked there, recorded as `portal:<email>`; the export command is on the page; and with the three Stripe variables the team plan is bought through Stripe Checkout, the signed webhook moving the plan (`stripe:<event>` in the audit trail) and the customer portal handling cancellation. Sessions are a signed cookie, `SameSite=Strict`, and every write needs a JSON body: one over 64 KB is answered 413, one that is not JSON 400, and any other failure a plain 500 with the detail in the portal's log, never in the answer. Each member has a role (`owner`, `admin`, `reviewer`, `readonly`), an account can turn on TOTP MFA, and the operator can set up single sign-on through the tenant's own OIDC or SAML identity provider with `log-admin sso set`; the [hosted log reference](https://docs.agent-custody.dev/reference/hosted) lists the routes. With `--registry-key-env NAME` (or `--registry-signer-url`) and `--portal-url`, the portal also runs the [agent registry](agent-registry.md): a tenant registers its agents by their did:keys, and the portal signs their passports. SAML needs `@node-saml/node-saml` beside the CLI. The compose file runs it as the `portal` service at `PORTAL_HOST`. The root paths serve the tenant `default`, created on first start with `--log-id`, and `--token-env` still works for it. The key that signs tree heads can live in its own process: `agent-custody signer --key keys/log.key --port 8790 --token-env SIGNER_TOKEN` holds it and answers `POST /sign` with the shared secret and `GET /keys` to anyone; the log server then runs with `--signer-url http://signer:8790/ --signer-token-env SIGNER_TOKEN` instead of `--key`, and the process that faces the internet never holds the key. Either way the log serves its keys at `/.well-known/agent-custody-log.json`, current key first and retired keys (`--retired-key old.pub`) after it, so verifiers fetch and pin them with `verify --log-url` and `audit --log-url` rather than receiving a key file from the operator. With `--checkpoint-dir <dir>` the server publishes a signed checkpoint, every `--checkpoint-every` seconds (default 300), for each log whose tree has grown, and every `--checkpoint-heartbeat` seconds (default 21600, six hours) for a log that has not, so a quiet log's latest checkpoint is never more than six hours old and the monitor can tell quiet from stalled, as `<dir>/<tenant>/<treeSize>.json` and `latest.json`, and with a database also as rows; `GET /checkpoints?since=<size>` and `GET /t/<tenant>/checkpoints` list them. Serve the directory read-only from a second host, so the record of what the log signed does not depend on the log's API being up; a verifier who kept an earlier head audits against a later checkpoint with `audit --older <bundle> --newer <checkpoint> --log-url <url>`. With `--admin-token-env ADMIN_TOKEN` (Postgres only) the server also serves the operator's page at `/admin` and its API under `/admin/`: list and create tenants, mint a token that is shown once beside the tenant's welcome sheet, revoke tokens, disable tenants. Everything under `/admin`, the page included, needs the admin token: the browser asks for it (any user name, the token as the password) and an API client sends it as a bearer; a handful of wrong attempts from one address are throttled for a minute. Every change made there or with `log-admin` is recorded: who (the name entered at the browser prompt and the address, `bearer` for an API client, or the user and host for the command line), what (`tenant.add`, `tenant.disable`, `token.add`, `token.revoke`), which tenant, and the detail, never the token itself; the page shows it under Activity, `GET /admin/audit?tenant=&limit=` and `log-admin audit` list it, and a tenant reads their own rows at `GET /t/<name>/audit` with their token. Nothing else is stored by the page. Behind a reverse proxy, start the server with `--trust-proxy` so those per-address limits key on `X-Forwarded-For` instead of on the proxy's own address, and only there, since the header is otherwise the client's to forge. `--public-url` and `--checkpoints-url` fill the sheet in. The witness closes the last gap: `agent-custody witness --key witness.key --log-url <url> --checkpoints-url <url> --out <dir> [--tenant <name>]...` runs on a machine the log's operator does not control, fetches each watched log's latest checkpoint, verifies it against the log's published keys, proves with the log's consistency proof that it extends the last head the witness signed, and countersigns it into `<dir>/<tenant>/<size>.json` and `latest.json`; a checkpoint that does not extend, or a second history at the same size, gets `ALARM.json` instead. Its key document is `<dir>/.well-known/agent-custody-witness.json`. Serve `<dir>` from the witness's own host; verifiers add `--witness-url` (or `--witness-key`) to `audit`, and the newer head must then carry the witness's signature. Two more things an operator needs. `agent-custody log-check --log-url <url> --checkpoints-url <url> [--witness-url <url>] [--tenant <name>]... [--max-lag <seconds>]` is the outside monitor: it verifies the head against the published keys, that the latest checkpoint verifies and keeps up with the head, that the head extends the checkpoint, and, with a witness, that the witness has countersigned, keeps up, and has raised no alarm; it exits 1 on any failure, so cron or a scheduled workflow on a machine that is not the log's turns it into an alert. `GET /health` on the server is the liveness check for a load balancer. And `GET /admin/usage?month=YYYY-MM`, on the admin page and as `/admin/usage.csv`, is the metering: appends per tenant for the month, leaves in total, live tokens, the numbers any invoice rests on. A tenant needs none of that to leave with their evidence: `agent-custody log-export --log-url <url> --tenant <name> --token-env AGENT_CUSTODY_LOG_TOKEN --out <dir>` fetches, with their own token, every leaf hash (`GET /t/<name>/leaves?since=&limit=`, pages of up to ten thousand), the signed head, the published keys, the signed checkpoints, their own usage (`GET /t/<name>/usage?month=`), and the administrative actions on their tenant (`GET /t/<name>/audit`, into `audit.json`), checks that the head and every checkpoint verify against the keys and that the leaves fetched hash to their roots, and writes `log.jsonl` in the format `verify --log` and `audit --log` read, so the export verifies receipts with no server at all. It exits 1 and says what did not add up if anything does not. Both routes answer only to that tenant's token. [deploy/](../../deploy/README.md) runs the server, the signer, Postgres, and the checkpoints host as containers, and [deploy/witness/](../../deploy/witness/) the witness.
129
129
 
130
130
  `otel`, optional in both the gateway and SDK configs, sends every receipt to the collector you already run as one span over OTLP/HTTP, after the receipt is issued: `"otel": { "url": "http://localhost:4318", "headersEnv": { "x-api-key": "OTEL_KEY" }, "serviceName": "support-agents" }`. The span's trace id is the receipt id, its attributes carry the tool, agent, principal, execution status, policy decision, and log position, and its status is an error only when the upstream failed or errored, since a denial is the policy working. A door receipt records an inbound request, so its span kind is `SERVER`; every other issuer's span is `CLIENT`. Export is best effort: a collector that is down or refuses costs a line on stderr, never a receipt. Tutorial 18 shows it against a stand-in collector.
131
131
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-custody/receipts",
3
- "version": "0.16.11",
3
+ "version": "0.16.13",
4
4
  "mcpName": "io.github.svayatta/agent-custody",
5
5
  "description": "Proof of what your AI agents did. Give your agents real power, without losing control of them: signed, verifiable receipts for tool calls, an MCP gateway with Cedar or Rego policy, and a Merkle transparency log.",
6
6
  "license": "Apache-2.0",
@@ -70,6 +70,7 @@
70
70
  "test": "vitest run",
71
71
  "coverage": "vitest run --coverage.enabled",
72
72
  "demo": "tsx scripts/demo.ts",
73
+ "demo:refund": "node examples/59-refund-demo.ts",
73
74
  "vectors": "tsx scripts/vectors.ts",
74
75
  "bench": "node scripts/hot-path-bench.ts"
75
76
  },