@agent-custody/receipts 0.16.9 → 0.16.11
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.
- package/README.md +24 -9
- package/dist/approval-requests.d.ts +114 -0
- package/dist/approval-requests.js +198 -0
- package/dist/approval.d.ts +8 -0
- package/dist/approval.js +10 -3
- package/dist/check.js +2 -0
- package/dist/cli.js +96 -16
- package/dist/completeness.d.ts +28 -2
- package/dist/completeness.js +102 -9
- package/dist/config.d.ts +3 -0
- package/dist/config.js +6 -1
- package/dist/console-page.js +87 -2
- package/dist/console.js +72 -0
- package/dist/crypto.d.ts +2 -0
- package/dist/crypto.js +2 -1
- package/dist/delegation.d.ts +1 -1
- package/dist/delegation.js +19 -2
- package/dist/did-key.d.ts +11 -0
- package/dist/did-key.js +86 -0
- package/dist/door-app.d.ts +3 -0
- package/dist/door-app.js +10 -0
- package/dist/door-core.d.ts +373 -0
- package/dist/door-core.js +743 -0
- package/dist/door-form.d.ts +6 -0
- package/dist/door-form.js +97 -0
- package/dist/door-worker.d.ts +133 -0
- package/dist/door-worker.js +259 -0
- package/dist/door.d.ts +18 -294
- package/dist/door.js +62 -722
- package/dist/gateway-http.d.ts +1 -6
- package/dist/gateway-http.js +2 -19
- package/dist/gateway.js +24 -3
- package/dist/grant-header.d.ts +8 -0
- package/dist/grant-header.js +19 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -2
- package/dist/issue.d.ts +2 -16
- package/dist/issue.js +2 -12
- package/dist/log-http.d.ts +37 -0
- package/dist/log-http.js +74 -0
- package/dist/log-sink.d.ts +3 -37
- package/dist/log-sink.js +5 -71
- package/dist/log.d.ts +2 -27
- package/dist/log.js +2 -173
- package/dist/merkle.d.ts +27 -0
- package/dist/merkle.js +175 -0
- package/dist/object-issuer.d.ts +29 -0
- package/dist/object-issuer.js +172 -0
- package/dist/receipt-pending.d.ts +16 -0
- package/dist/receipt-pending.js +14 -0
- package/dist/web-bot-auth.d.ts +26 -6
- package/dist/web-bot-auth.js +116 -56
- package/docs/approvals.md +33 -0
- package/docs/completeness.md +82 -12
- package/docs/console.md +11 -4
- package/docs/door-middleware.md +11 -0
- package/docs/door-quickstart.md +53 -17
- package/docs/door-signals.md +5 -5
- package/docs/door-worker.md +81 -0
- package/docs/door.md +38 -8
- package/docs/github-action.md +2 -2
- package/docs/threat-model.md +1 -1
- package/docs/tutorials.md +5 -0
- package/docs/verification.md +1 -1
- package/package.json +3 -1
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/receipts.json +1645 -1549
package/docs/door-quickstart.md
CHANGED
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
This page is for someone who runs a website or an API. In about fifteen minutes you run the door in front of a small stand-in site, write one policy for a sign-up form, and watch four arrivals: a bot that is refused and told how to pass the challenge, a bot that only claims to be an agent, a person who passes the challenge, and an agent that shows a passport. Then you verify the receipts with public keys only.
|
|
4
4
|
|
|
5
|
-
You need Node 22 or later
|
|
5
|
+
You need Docker and `curl`. No Docker? Node 22 or later does the same: read [Without Docker](#without-docker) first. The person in step 6 passes Cloudflare Turnstile with its public test keys, which needs no account but does call Cloudflare once. Everything else runs on your machine.
|
|
6
6
|
|
|
7
|
-
The door
|
|
7
|
+
The door runs from the gateway's container image. The same image runs every other `agent-custody` command on this page, so nothing is installed:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
alias agent-custody='npx -y -p @agent-custody/receipts@0.16.4 agent-custody'
|
|
11
10
|
mkdir door-quickstart && cd door-quickstart
|
|
11
|
+
IMAGE=ghcr.io/svayatta/agent-custody-gateway:0.16.11
|
|
12
|
+
alias agent-custody='docker run --rm --user "$(id -u):$(id -g)" -v "$PWD":/work -w /work -e TURNSTILE_SECRET $IMAGE'
|
|
12
13
|
```
|
|
13
14
|
|
|
15
|
+
Stay in this directory and this terminal for the whole page: the commands write their files here, and the later steps use the variables that the earlier steps set.
|
|
16
|
+
|
|
14
17
|
## 1. Keys
|
|
15
18
|
|
|
16
19
|
The door signs every receipt with its own key. The principal key belongs to whoever vouches for an agent: it signs the agent's passport, and the door trusts the passports it signs.
|
|
@@ -22,10 +25,11 @@ agent-custody keygen --dir keys --name principal
|
|
|
22
25
|
|
|
23
26
|
## 2. A stand-in site
|
|
24
27
|
|
|
25
|
-
Your real site goes here later. This one answers a page on `GET /` and accepts a sign-up on `POST /form
|
|
28
|
+
Your real site goes here later. This one answers a page on `GET /` and accepts a sign-up on `POST /form`. It runs in a container named `site`, on a network that only the door shares, so the door is the only way in:
|
|
26
29
|
|
|
27
30
|
```bash
|
|
28
|
-
|
|
31
|
+
docker network create door-quickstart
|
|
32
|
+
docker run -d --name site --network door-quickstart --entrypoint node $IMAGE -e 'require("http").createServer((q,s)=>{s.setHeader("content-type","text/plain");s.end(q.method==="GET"?"the sign-up page\n":"thanks, you are signed up\n")}).listen(3000)'
|
|
29
33
|
```
|
|
30
34
|
|
|
31
35
|
## 3. The policy
|
|
@@ -52,7 +56,7 @@ when { context.facts.arrival.class == "verified" };
|
|
|
52
56
|
```json
|
|
53
57
|
{
|
|
54
58
|
"identity": { "keyFile": "keys/door.key" },
|
|
55
|
-
"origin": { "url": "http://
|
|
59
|
+
"origin": { "url": "http://site:3000" },
|
|
56
60
|
"routes": [
|
|
57
61
|
{ "name": "page", "methods": ["GET"], "path": "/" },
|
|
58
62
|
{ "name": "form", "methods": ["POST"], "path": "/form" }
|
|
@@ -70,17 +74,27 @@ when { context.facts.arrival.class == "verified" };
|
|
|
70
74
|
}
|
|
71
75
|
```
|
|
72
76
|
|
|
73
|
-
`1x00000000000000000000AA` and the secret below are Cloudflare's [test keys](https://developers.cloudflare.com/turnstile/troubleshooting/testing/): every token passes, and the answer names the host `example.com`. Check the config before you start the door
|
|
77
|
+
`1x00000000000000000000AA` and the secret below are Cloudflare's [test keys](https://developers.cloudflare.com/turnstile/troubleshooting/testing/): every token passes, and the answer names the host `example.com`. Check the config before you start the door:
|
|
74
78
|
|
|
75
79
|
```bash
|
|
76
80
|
export TURNSTILE_SECRET=1x0000000000000000000000000000000AA
|
|
77
81
|
agent-custody check --config door.json
|
|
78
82
|
```
|
|
79
83
|
|
|
84
|
+
```text
|
|
85
|
+
warn origin: http://site:3000 is plain HTTP to a remote host; the relayed traffic is not encrypted on that leg
|
|
86
|
+
warn revokedGrants: no revokedGrants file: a grant cannot be revoked at this door before it expires
|
|
87
|
+
|
|
88
|
+
no errors, 2 warnings
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The last line must say `no errors`. The two warnings are correct for this page: the stand-in site is on a private network on your machine, and this page revokes no grant.
|
|
92
|
+
|
|
80
93
|
## 5. Start the door
|
|
81
94
|
|
|
82
95
|
```bash
|
|
83
|
-
|
|
96
|
+
docker run -d --name door --network door-quickstart --user "$(id -u):$(id -g)" -v "$PWD":/work -w /work \
|
|
97
|
+
-e TURNSTILE_SECRET -e DOOR_CONFIG=door.json -e DOOR_KEY=keys/door.key -p 127.0.0.1:8780:8780 $IMAGE door
|
|
84
98
|
curl -s http://127.0.0.1:8780/
|
|
85
99
|
```
|
|
86
100
|
|
|
@@ -88,14 +102,14 @@ curl -s http://127.0.0.1:8780/
|
|
|
88
102
|
the sign-up page
|
|
89
103
|
```
|
|
90
104
|
|
|
91
|
-
The page went through the door, so it already has a receipt.
|
|
105
|
+
The page went through the door, so it already has a receipt. If `curl` cannot connect, wait a second and try again. If it still cannot, `docker logs door` shows why the door did not start.
|
|
92
106
|
|
|
93
107
|
## 6. Four arrivals at the form
|
|
94
108
|
|
|
95
109
|
**A bot.** It presents nothing. The policy refuses it, and the 403 says how to pass the challenge, so your page can show the widget and try again:
|
|
96
110
|
|
|
97
111
|
```bash
|
|
98
|
-
curl -si -X POST http://127.0.0.1:8780/form -H 'content-type: application/json' -d '{"email":"a@example.com"}'
|
|
112
|
+
curl -si -X POST http://127.0.0.1:8780/form -H 'content-type: application/json' -d '{"email":"a@example.com"}' | tee bot.txt
|
|
99
113
|
```
|
|
100
114
|
|
|
101
115
|
```text
|
|
@@ -136,8 +150,8 @@ The class stays `unknown`: a passed challenge says the arrival solved a challeng
|
|
|
136
150
|
|
|
137
151
|
```bash
|
|
138
152
|
agent-custody grant --key keys/principal.key --principal agent-co --agent shopping-agent --scopes form --out grant.json
|
|
139
|
-
PASSPORT=$(
|
|
140
|
-
curl -si -X POST http://127.0.0.1:8780/form -H 'content-type: application/json' -H "x-agent-custody-grant: $PASSPORT" -d '{"email":"agent@example.com"}'
|
|
153
|
+
PASSPORT=$(base64 < grant.json | tr -d '\n=' | tr '+/' '-_')
|
|
154
|
+
curl -si -X POST http://127.0.0.1:8780/form -H 'content-type: application/json' -H "x-agent-custody-grant: $PASSPORT" -d '{"email":"agent@example.com"}' | tee agent.txt
|
|
141
155
|
```
|
|
142
156
|
|
|
143
157
|
```text
|
|
@@ -150,12 +164,18 @@ thanks, you are signed up
|
|
|
150
164
|
|
|
151
165
|
## 7. Verify the receipts
|
|
152
166
|
|
|
153
|
-
Every arrival left a receipt in `receipts/`, refused or not, and every one is in the log. A sign-up has two: the door commits it to the log before your site hears of it, then receipts the outcome.
|
|
167
|
+
Every arrival left a receipt in `receipts/`, refused or not, and every one is in the log. A sign-up has two: the door commits it to the log before your site hears of it, then receipts the outcome. Each answer carries its receipt id in the `x-agent-custody-receipt` header. Step 6 saved two answers, so read the two ids from them:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
BOT=$(tr -d '\r' < bot.txt | awk 'tolower($1)=="x-agent-custody-receipt:"{print $2}')
|
|
171
|
+
AGENT=$(tr -d '\r' < agent.txt | awk 'tolower($1)=="x-agent-custody-receipt:"{print $2}')
|
|
172
|
+
echo "$BOT $AGENT"
|
|
173
|
+
```
|
|
154
174
|
|
|
155
175
|
The refused bot, checked with the door's public key and the log:
|
|
156
176
|
|
|
157
177
|
```bash
|
|
158
|
-
agent-custody verify receipts
|
|
178
|
+
agent-custody verify receipts/$BOT.json --issuer-key keys/door.pub --log log.jsonl
|
|
159
179
|
```
|
|
160
180
|
|
|
161
181
|
```text
|
|
@@ -170,7 +190,7 @@ ISSUER: door (http), enforced in front of the business's own HTTP surface; the a
|
|
|
170
190
|
The agent, with the principal's key as well, so the passport is checked too:
|
|
171
191
|
|
|
172
192
|
```bash
|
|
173
|
-
agent-custody verify receipts
|
|
193
|
+
agent-custody verify receipts/$AGENT.json --issuer-key keys/door.pub --principal-key keys/principal.pub --log log.jsonl
|
|
174
194
|
```
|
|
175
195
|
|
|
176
196
|
```text
|
|
@@ -185,14 +205,30 @@ agent attested shopping-agent
|
|
|
185
205
|
policy observed allow [policy2] policy fbb0e37266c4
|
|
186
206
|
```
|
|
187
207
|
|
|
188
|
-
The output above is cut to the lines that matter; the full report lists every check. The request body is not in either receipt, only its digest: the door withholds by default ([what a receipt records](door.md#what-a-receipt-records-of-the-query-and-the-body)).
|
|
208
|
+
The output above is cut to the lines that matter; the full report lists every check, and your ids, digests, and leaf numbers differ. The request body is not in either receipt, only its digest: the door withholds by default ([what a receipt records](door.md#what-a-receipt-records-of-the-query-and-the-body)).
|
|
209
|
+
|
|
210
|
+
Stop the door and the stand-in site, and remove their network:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
docker rm -f door site && docker network rm door-quickstart
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Without Docker
|
|
217
|
+
|
|
218
|
+
With Node 22 or later, the same page runs the CLI from npm. Four steps change, and every other command stays as it is:
|
|
219
|
+
|
|
220
|
+
- **The setup.** The alias is `alias agent-custody='npx -y -p @agent-custody/receipts@0.16.11 agent-custody'`, and there is no `IMAGE`.
|
|
221
|
+
- **Step 2.** Start the stand-in site with `node -e 'require("http").createServer((q,s)=>{s.setHeader("content-type","text/plain");s.end(q.method==="GET"?"the sign-up page\n":"thanks, you are signed up\n")}).listen(3000,"127.0.0.1")' &`.
|
|
222
|
+
- **Step 4.** In `door.json`, the origin is `"http://127.0.0.1:3000"`. The check then gives one warning, not two.
|
|
223
|
+
- **Step 5.** Start the door with `agent-custody door --config door.json --port 8780 &`.
|
|
189
224
|
|
|
190
|
-
|
|
225
|
+
At the end, stop both with `kill %1 %2`.
|
|
191
226
|
|
|
192
227
|
## Before you put it in front of your own site
|
|
193
228
|
|
|
194
229
|
- **Use your own Turnstile keys.** Put the widget on the page that posts the form, set `siteKey`, the secret in `TURNSTILE_SECRET`, and `hostnames` to your site's hosts. A token serves one request, so the page takes a new one for each submit ([challenging a human](door.md#what-the-door-knows-about-an-arrival)).
|
|
195
230
|
- **Make the door the only way in.** A request that reaches your site some other way leaves no receipt. Bind the site to a private address, or have it require a header that only the door adds (`origin.headerEnv`).
|
|
231
|
+
- **Run it as a service.** [deploy/door](../../../deploy/door/README.md) has a compose file, Kubernetes manifests, and a systemd unit for the same image, and the configs for a door behind your own nginx or Envoy.
|
|
196
232
|
- **Behind your own TLS proxy,** set `trustProxy` so the door reads the client's address, not the proxy's.
|
|
197
233
|
- **A passport alone is bearer-grade.** The door checks its signature, window, and scope, not that the sender holds the agent's key. Keep the time to live short. An agent that also signs its requests per Web Bot Auth, with `webBotAuth` configured, binds the passport to itself: see [Web Bot Auth signatures](door.md#web-bot-auth-signatures).
|
|
198
234
|
- **Read [the door](door.md)** for every field of the config, and [door signals](door-signals.md) for what each fact about an arrival does and does not establish, before you write a policy for a route that matters.
|
package/docs/door-signals.md
CHANGED
|
@@ -17,15 +17,15 @@ Three labels run through the table:
|
|
|
17
17
|
| `class: "unknown"` | observed | Nothing was presented | That the arrival is a person. A browser, a crawler, and a script that sends no headers are all `unknown`. There is no `human` class, and a policy that admits `unknown` on a route admits everything on that route |
|
|
18
18
|
| `grant: "verified"` | checked | As `class: "verified"` | |
|
|
19
19
|
| `grant: "out-of-scope"` | checked | The grant verified and is valid, but this route is not among its scopes. `subject` is the agent it names | That the agent may do anything here. The principal did not grant this route |
|
|
20
|
-
| `grant: "invalid"` | checked | The grant did not verify against a trusted key, did not decode, or is outside its window
|
|
20
|
+
| `grant: "invalid"` | checked | The grant did not verify against a trusted key, did not decode, or is outside its window; or it, or a grant above it in its chain, names its agent by a did:key that does not decode to an Ed25519 key, or that is not the key in its `agentKey`. `grantError` says which | Who signed it. A grant from an untrusted principal is `invalid` even when it is genuine. A did:key grant that is not `invalid` and has no request signature is `verified` without any proof that the sender holds the key: it is bearer-grade like any grant. A request signature by the did:key's own key binds it: see `signature: "verified"` |
|
|
21
21
|
| `grant: "revoked"` | checked | The grant verified against a trusted key, and it, or a grant above it in its chain, is in the door's `revokedGrants` file; or that file could not be read, which revokes every grant until it can. `grantError` says which | That the agent misbehaved. The operator withdrew the grant, for whatever reason; the revocation file does not record why |
|
|
22
|
-
| `grant: "wrong-sender"` | checked | The grant verified and is in scope, and the request is signed, verifiably, by a signature agent the grant does not name. The arrival is `claimed` | Which of the two is lying. The grant was handed on or taken; the door does not admit it as the agent it names |
|
|
22
|
+
| `grant: "wrong-sender"` | checked | The grant verified and is in scope, and the request is signed, verifiably, by a signature agent, or by the key of a did:key, that the grant does not name. The arrival is `claimed` | Which of the two is lying. The grant was handed on or taken; the door does not admit it as the agent it names |
|
|
23
23
|
| `grant: "absent"` | observed | No grant header | |
|
|
24
24
|
| `subject` | checked only when `class` is `verified` | The agent a verified grant names; else the signature agent of a verified signature; else the declared name or the agent a rejected grant named; else `unknown` | For a `claimed` arrival, anything. It is recorded so the receipt shows what was asserted; the Cedar `principal` is `Agent::"unknown"` for it |
|
|
25
25
|
| `declared` | a claim | The `x-agent-custody-agent` header, as sent, cut at 200 characters | That the agent is that agent. Anyone can send the header. A permit on a declared name admits whoever types it |
|
|
26
|
-
| `signature: "verified"` | checked, against the agent's directory | An RFC 9421 signature tagged `web-bot-auth`, Ed25519, covering `@authority` (one of `authorities`) and the `Signature-Agent` member, made at most `maxAgeSeconds` ago, with a nonce not seen before, verified with the key whose thumbprint is its keyid in the directory the door fetched over https from the `Signature-Agent` origin, an origin listed in `agents`. `signatureAgent` and `signatureKeyid` name the agent and the key. With a grant for the same agent, the grant is bound to its sender | That the body, the method, or the path is what the agent sent, unless the signature covers them (a minimal one covers the authority only), that the origin is a crawler you know or behaves well, or that a second door has not seen the nonce. The directory's own response signatures are not checked |
|
|
26
|
+
| `signature: "verified"` | checked, against the agent's directory | An RFC 9421 signature tagged `web-bot-auth`, Ed25519, covering `@authority` (one of `authorities`) and the `Signature-Agent` member, made at most `maxAgeSeconds` ago, with a nonce not seen before, verified with the key whose thumbprint is its keyid in the directory the door fetched over https from the `Signature-Agent` origin, an origin listed in `agents`. `signatureAgent` and `signatureKeyid` name the agent and the key. With a grant for the same agent, the grant is bound to its sender. For a did:key agent: the same signature with the did:key as its keyid and no `Signature-Agent`, verified with the key that the did:key names, with no directory, and recorded as `verified` only when a verified grant names that did:key; `signatureAgent` and `signatureKeyid` are then the did:key. In every other case a did:key signature is `invalid` | That the body, the method, or the path is what the agent sent, unless the signature covers them (a minimal one covers the authority only), that the origin is a crawler you know or behaves well, or that a second door has not seen the nonce. The directory's own response signatures are not checked |
|
|
27
27
|
| `signature: "invalid"` | checked | A signature arrived and one check failed: no `web-bot-auth` tag, a missing parameter, an algorithm other than Ed25519, a component not covered or not supported, an agent not in `agents` or not https, outside the window, another authority, a repeated nonce, a redirect or a bad directory, a key not in it, or a signature that does not verify. `signatureError` says which | That the arrival is hostile. A clock off by more than `clockSkewSeconds` and a forgery both land here |
|
|
28
|
-
| `signature: "unavailable"` | observed | The directory did not answer in time or answered a non-200, or the door's nonce
|
|
28
|
+
| `signature: "unavailable"` | observed | The directory did not answer in time or answered a non-200, or the door's nonce store is full or cannot be reached | Anything about the arrival. It is the network's or the door's state, like a challenge's `unavailable`; a policy that wants the agent through during a directory outage needs a grant as well |
|
|
29
29
|
| `signature: "unchecked"` | a claim | A `Signature-Input` arrived, and the door has no `webBotAuth` config | That the signature is valid, or who signed |
|
|
30
30
|
| `signature: "absent"` | observed | No signature headers | |
|
|
31
31
|
| `remote` | observed | The socket's address, or with `trustProxy` the last address in `X-Forwarded-For`, the one your proxy appended | Who the person or program is. One address serves a whole office, a mobile carrier, or a cloud region; one program can use many |
|
|
@@ -57,7 +57,7 @@ when { context.facts.arrival.class == "verified" };
|
|
|
57
57
|
|
|
58
58
|
`agent-custody check` warns about a permit that names an agent without that condition.
|
|
59
59
|
|
|
60
|
-
A route that needs to know the sender holds the agent's key requires the signature beside the grant. A grant under another agent's signature is `wrong-sender`, so this holds only for a grant bound to its sender:
|
|
60
|
+
A route that needs to know the sender holds the agent's key requires the signature beside the grant. A grant under another agent's signature is `wrong-sender`, so this holds only for a grant bound to its sender, by its agent's Web Bot Auth signature or by a signature with the key of its did:key agent:
|
|
61
61
|
|
|
62
62
|
```cedar
|
|
63
63
|
permit(principal == Agent::"https://crawler.example", action == Action::"api", resource)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# The door as a Cloudflare Worker
|
|
2
|
+
|
|
3
|
+
> For a site already on Cloudflare. How the door works is in [the door](door.md); every field is in [the reference](../../../site/reference/door.md). The template and the deploy steps are in [deploy/door/cloudflare-worker](../../../deploy/door/cloudflare-worker/README.md).
|
|
4
|
+
|
|
5
|
+
The Worker runs the door's own decision loop (`src/door-core.ts`) at Cloudflare's edge, so each request to the site reaches the Worker first. It classifies the arrival (`verified`, `claimed`, or `unknown`), decides with the site's Cedar policy for the route, and relays an allowed request to the origin with `fetch`. It answers a refused one with the door's refusal. Every decision gets a door receipt, the same receipt the Node door writes: issuer kind `door`, framework `cloudflare-worker`. The receipt goes to the log over HTTP and to an R2 bucket. `agent-custody verify` checks it with the Worker's public key and the log, as it checks any door receipt.
|
|
6
|
+
|
|
7
|
+
It is the same code as the reverse proxy, the in-process door, and authz mode, with different I/O:
|
|
8
|
+
|
|
9
|
+
| | Node door | Worker |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| signing key | `identity.keyFile` | the `DOOR_KEY` secret |
|
|
12
|
+
| policy | `policyFile`, re-read when it changes | the `DOOR_POLICY` variable; a change is a deploy |
|
|
13
|
+
| config | `door.json` | the `DOOR_CONFIG` variable, without the fields that name files |
|
|
14
|
+
| receipts | the receipts directory | the `RECEIPTS` R2 bucket, same names: `<id>.json`, `<id>.authorization.json`, `salts/<id>.json`, `outbox/<id>.json` |
|
|
15
|
+
| log | `logFile` or `log.url` | `LOG_URL`, its keys pinned in `LOG_KEYS`, token in the `LOG_TOKEN` secret |
|
|
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 |
|
|
18
|
+
| the arrival's address | the socket, or `X-Forwarded-For` with `trustProxy` | `CF-Connecting-IP`, which Cloudflare sets |
|
|
19
|
+
| Web Bot Auth nonces | one process's memory | a Durable Object per nonce, which every isolate reaches (the `NONCES` binding) |
|
|
20
|
+
| arrival rates | one process's memory | one isolate's memory |
|
|
21
|
+
|
|
22
|
+
## What reaches the policy
|
|
23
|
+
|
|
24
|
+
Everything the Node door gives it: the arrival fact, the request's arguments, and the grant. Web Bot Auth works unchanged. The request's own `Signature`, `Signature-Input`, and `Signature-Agent` headers reach the Worker, and directories are fetched with `fetch` and cached in the isolate. A grant in `X-Agent-Custody-Grant` or `Authorization: Bearer` is checked as at any door.
|
|
25
|
+
|
|
26
|
+
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
|
+
|
|
28
|
+
## When R2 or the log is unavailable
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
A safe request whose receipt the log will not take is relayed anyway. Its receipt is signed and kept in `outbox/` in the bucket, the answer carries `x-agent-custody-log-pending: true`, and the cron appends it once the log is back.
|
|
33
|
+
|
|
34
|
+
What is lost when R2 is down for a safe request: the log takes the receipt's leaf, but the bundle cannot be stored. The origin has already answered, and its answer is not relayed. The client gets 500 saying that the origin acted and that the request was not recorded, so nobody retries it. The log then holds a leaf whose bundle exists nowhere. If both the log and R2 are down, the receipt cannot be kept in the outbox either, and the client gets the same 500.
|
|
35
|
+
|
|
36
|
+
There is no lock between isolates. Two flushes at once can each append the same outbox entry, which puts the receipt in the log under two leaves. Either inclusion proves it.
|
|
37
|
+
|
|
38
|
+
## Limits
|
|
39
|
+
|
|
40
|
+
- **Bundle.** 517 KB of JavaScript (115 KB gzipped), plus Cedar's WebAssembly: 4.3 MB, 1.42 MB gzipped. That is about 1.5 MB compressed, within the free plan's 3 MB and the paid plans' 10 MB.
|
|
41
|
+
- **CPU time.** A warm decision for a `GET`, run locally in workerd (Miniflare 4.20260730), takes 3.2 ms median and 3.5 ms at the 90th percentile. That is wall time, including a local log append of about 0.6 ms and an R2 write. workerd does not expose CPU time to the code it runs, so the figure to plan with is the one in the Workers dashboard of a real deployment. The first request of an isolate also instantiates Cedar's module and parses the policy, which is not in that figure. The free plan allows 10 ms of CPU per request, which a cold start may exceed. The paid plans allow far more.
|
|
42
|
+
- **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
|
+
- **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
|
+
- **Arrival rates live in one isolate too.** A pace rule sees what one isolate counted.
|
|
45
|
+
|
|
46
|
+
## Web Bot Auth nonces
|
|
47
|
+
|
|
48
|
+
Cloudflare runs many isolates, in many places, and starts new ones at will. If each isolate remembered nonces in its own memory, a captured signature refused by the isolate that saw it would be accepted once by any other, until `maxAgeSeconds`. So the Worker keeps each nonce in a Durable Object, `DoorNonce`, named by the signature's agent, key id, and nonce. Every isolate that sees that nonce reaches the same object, wherever it runs. The object answers one claim at a time: of two arrivals with one nonce, even at two isolates at once, one is verified and the other is a replay. It holds the nonce until the signature could no longer be accepted (the earlier of `expires` and `created + maxAgeSeconds`, plus `clockSkewSeconds`), and then 60 seconds more, before an alarm empties it. That deadline is on the isolate's clock, and the object reads its own. Without the extra minute, an object whose clock ran ahead would forget a nonce while the isolate still accepted its signature. The isolate refuses the signature after its own deadline whatever the object holds, so the extra minute refuses nothing that would otherwise verify.
|
|
49
|
+
|
|
50
|
+
A nonce is claimed only after the signature verifies, so a forged signature cannot spend the nonce of the request it copies. A replay costs a directory lookup (usually cached) and a signature check before it is refused.
|
|
51
|
+
|
|
52
|
+
With `webBotAuth` in `DOOR_CONFIG`, the Worker needs the `NONCES` binding and answers 500, relaying nothing, without it. The template's `wrangler.toml` declares it, and `wrangler deploy` creates the class. If the object cannot be reached, throws, or does not answer within 3 seconds, the signature is `unavailable`, as when a Node door's nonce memory is full. It is never `verified`. `maxNonces` bounds a Node door's memory and does not apply to the Worker.
|
|
53
|
+
|
|
54
|
+
What it costs: one Durable Object request, one storage write, and one alarm for each verified signature that carries a nonce. The object is created near the isolate that made the first claim, so a replay sent from far away waits for a round trip there.
|
|
55
|
+
|
|
56
|
+
Workers KV was not used. It is eventually consistent: a nonce written at one location can take up to a minute to be seen at another, so a replay sent there in that time would be accepted.
|
|
57
|
+
|
|
58
|
+
## The signing key
|
|
59
|
+
|
|
60
|
+
The key is a Worker secret: stored by Cloudflare, given to the Worker as a binding, and readable by any code deployed to that Worker. Anyone who can deploy to the Worker, or read its bindings through the account, can sign receipts as the door. It is not held in a hardware module. Give deploy rights to as few people as you would give the key file of a Node door, and rotate it the same way. Rotating means a new key, a new public key handed to whoever verifies, and the old public key kept for older receipts.
|
|
61
|
+
|
|
62
|
+
## What was checked, and how
|
|
63
|
+
|
|
64
|
+
- `test/door-worker.test.ts` builds the Worker with the same script `wrangler deploy` runs and serves it in workerd, with local stand-ins for the origin, the log, and a crawler's key directory. It checks the following:
|
|
65
|
+
- an unknown arrival on a protected route is refused and never reaches the origin;
|
|
66
|
+
- a verified Web Bot Auth arrival is relayed and its receipt verifies;
|
|
67
|
+
- a forged signature, or the same signature twice, is not verified;
|
|
68
|
+
- with two copies of the Worker (two isolates) sharing one `DoorNonce` namespace, a signature verified at one is refused at the other, and of the same signature sent to both at once only one is verified;
|
|
69
|
+
- a Worker whose nonce object fails gives `unavailable`, not `verified`;
|
|
70
|
+
- a grant is checked at the edge;
|
|
71
|
+
- a precommit request is not relayed when the log is down;
|
|
72
|
+
- a safe request's receipt goes to the outbox and the cron appends it;
|
|
73
|
+
- the Bot Management fact is recorded;
|
|
74
|
+
- the Worker's Ed25519 signature is byte for byte the one Node makes over the same bytes;
|
|
75
|
+
- `agent-custody verify` accepts a Worker receipt;
|
|
76
|
+
- a config that names a file is refused with nothing relayed.
|
|
77
|
+
- `test/door-worker-io.test.ts` checks the bucket issuer in Node, where a store can be made to fail: a precommit request whose authorization the bucket cannot store is not relayed. It also checks that a config with `webBotAuth` is refused without `NONCES`, and that a nonce object answering an error or no claim throws rather than answering one.
|
|
78
|
+
- `test/door.test.ts` runs `DoorNonce` with its clock 5 seconds ahead of the verifier's: a replay one second before the verifier's deadline is still refused.
|
|
79
|
+
- [56-door-worker.ts](../examples/56-door-worker.ts) is the same run as a tutorial.
|
|
80
|
+
|
|
81
|
+
A deployment to Cloudflare itself, with the receipts it produced, is not recorded here yet.
|
package/docs/door.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
The gateway stands between an agent and the tools it uses. The door stands between the world and your own HTTP surface: a website, an API, a form. Every arrival, a browser, an API client, a crawler, or an agent acting for someone, is classified by what it presented, decided by a Cedar policy for the route it hit, relayed to your origin or refused, and receipted either way. The receipt is the same signed, logged, independently verifiable receipt the gateway issues, with `issuer.kind: "door"`.
|
|
6
6
|
|
|
7
|
-
New to the door? [Put the door in front of a site](door-quickstart.md) walks through one form in about fifteen minutes. A Node site can run the same decision loop in its own process instead, as Express middleware or around a Next.js route handler: [the door in your Node app](door-middleware.md). Already run nginx or Envoy? The door can answer their authz checks instead of relaying, and the site keeps its proxy: [behind nginx or Envoy](#behind-nginx-or-envoy-authz-mode). A site in Go, Rails, Django, or Spring can ask the same check from a middleware: [the door in Go, Rails, Django, and Spring](door-languages.md).
|
|
7
|
+
New to the door? [Put the door in front of a site](door-quickstart.md) walks through one form in about fifteen minutes. A Node site can run the same decision loop in its own process instead, as Express middleware or around a Next.js route handler: [the door in your Node app](door-middleware.md). Already run nginx or Envoy? The door can answer their authz checks instead of relaying, and the site keeps its proxy: [behind nginx or Envoy](#behind-nginx-or-envoy-authz-mode). A site in Go, Rails, Django, or Spring can ask the same check from a middleware: [the door in Go, Rails, Django, and Spring](door-languages.md). A site already on Cloudflare can run the door at the edge, as a Worker: [the door as a Cloudflare Worker](door-worker.md).
|
|
8
8
|
|
|
9
9
|
This is the first piece of the agent front door. It answers "what may this arrival do here" and "what did it do, provably". It does not yet answer "is this an agent" for web traffic: that is detection, and the door records only what it can check. An agent that wants to be known can say so in a way the door checks: a grant, or a [Web Bot Auth signature](#web-bot-auth-signatures). Read [what the door knows](#what-the-door-knows-about-an-arrival) before writing a policy.
|
|
10
10
|
|
|
@@ -49,9 +49,9 @@ The door records one fact for every arrival, `arrival`, observed by the door its
|
|
|
49
49
|
| --- | --- | --- |
|
|
50
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 |
|
|
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
|
-
| `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 the grant does not name |
|
|
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
|
-
| `signatureAgent`, `signatureKeyid` | strings | the `Signature-Agent` origin and the keyid the signature named. Checked only when `signature` is `verified` |
|
|
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
56
|
| `remote` | string | the arrival's address |
|
|
57
57
|
| `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 |
|
|
@@ -67,9 +67,13 @@ There is no `human` class. The door cannot tell a person from a program that pre
|
|
|
67
67
|
|
|
68
68
|
**A grant alone is bearer-grade; a grant under its agent's signature is bound to its sender.** The door checks the grant's signature, window, and scope. On its own, that does not show that the sender holds the agent's key. Anyone who holds the grant's bytes is that agent until the grant expires, and every verified receipt carries the grant in `delegation`, so a person who can read one receipt can replay its grant. When the request also carries a Web Bot Auth signature that the door verified, and the grant names that signature agent (`"agent": "https://crawler.example"`), the grant is bound to its sender: a thief has the grant's bytes but not the agent's signing key, and a captured signature serves one request (its nonce) for at most `maxAgeSeconds`. A grant presented under another agent's signature is `wrong-sender`, and the arrival is `claimed`. A grant with no signature, or with one that did not verify, is still verified, bearer-grade, as before, so a route that needs the binding says so in its policy: `context.facts.arrival.grant == "verified" && context.facts.arrival.signature == "verified"` holds only for a bound grant, since a mismatch makes `grant` `wrong-sender`. For bearer grants, issue door grants with short lifetimes (minutes, not days), scope them to the routes they need, bound what a route allows per call in the policy, and treat receipt files and logs as holding live credentials until those grants expire.
|
|
69
69
|
|
|
70
|
+
**A did:key agent.** <a id="a-did-key-agent"></a>A grant may name its agent by a [did:key](https://w3c-ccg.github.io/did-key-spec/), the identifier of its Ed25519 key, `did:key:z6Mk...`: `agent-custody grant --agent-key agent.pub --did-key ...` issues one. The door checks the identifier after the principal's signature, on the grant and on every grant above it in its chain, with the check that the gateway and the verifiers use (`verifyDelegation`): it must decode to an Ed25519 key, and when that grant also carries `agentKey`, that must be the same key. A parent's `agentKey` is what verified the link below it, so a parent whose did:key and `agentKey` disagree makes the arrival `claimed` too, with `link <n>` in `grantError`. An identifier longer than 100 characters is refused before it is decoded. Either failure makes the arrival `claimed` with `grant: "invalid"` and the reason in `grantError`, because the grant says two things about who the agent is, or something that names no key. A grant that checks is `verified`, as any other, with the did:key as `subject`, the Cedar principal (`Agent::"did:key:z6Mk..."`), and the receipt's agent, attested. A did:key says which key; it does not prove that the sender holds it. Alone, a did:key grant is bearer-grade like any grant, and a Web Bot Auth signature names an https origin, not a did:key, so a did:key grant under a signature is `wrong-sender`.
|
|
71
|
+
|
|
72
|
+
**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
|
+
|
|
70
74
|
**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.
|
|
71
75
|
|
|
72
|
-
|
|
76
|
+
<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
|
|
73
77
|
|
|
74
78
|
```cedar
|
|
75
79
|
permit(principal, action == Action::"refund", resource)
|
|
@@ -80,6 +84,32 @@ and a refused arrival that has not passed is told how in the 403 body: `challeng
|
|
|
80
84
|
|
|
81
85
|
**A token serves one request.** Turnstile and hCaptcha refuse a token they have seen (`timeout-or-duplicate`, `already-seen-response`), and the door keeps no pass between requests: it does not set a cookie or remember an address. So the page must take a new token for every request it sends to a challenged route, and for every retry: call `turnstile.reset()` or `hcaptcha.reset()` after each request, and wait for the new token before the next. The door checks the token before it reads the body, so a request refused for its size (413), its path (400), or by the policy has used its token too. A second request that sends the same token is `failed`, and the person sees another 403. The outcome is a signal, not a class: a `verified` agent that also passes a challenge is still the agent its grant names, and an `unknown` arrival that passes is still `unknown`, with `challenge.outcome: "passed"` beside it. What the provider's pass means, and what it does not, is in [door signals](door-signals.md). Passkeys are not a provider here: a passkey proves possession of a credential the site registered, which is a login, not a challenge, and belongs to the origin.
|
|
82
86
|
|
|
87
|
+
### Protecting a form with one line
|
|
88
|
+
|
|
89
|
+
A form on a static site cannot set a header, and the door reads the challenge token from one. With `challenge` configured, the door serves a script that bridges the two, at `/.well-known/agent-custody-door/form.js`. The page adds one line:
|
|
90
|
+
|
|
91
|
+
```html
|
|
92
|
+
<script src="/.well-known/agent-custody-door/form.js" defer></script>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The script is built from the challenge config: the provider, the public site key, the header, and the action. The secret is never in it. In the browser it does the following:
|
|
96
|
+
- It loads the provider's script (`challenges.cloudflare.com` for Turnstile, `js.hcaptcha.com` for hCaptcha) and renders the widget in every form on the page whose method is POST and whose action is on the page's own origin. A GET form, or one that posts to another site, is left alone. To protect only some forms, give a selector on the tag: `<script src="..." data-forms="#contact" defer></script>`.
|
|
97
|
+
- On submit it sends the form with `fetch`, the widget's token in the door's challenge header and the form's fields as the browser would send them (form-encoded, or multipart when the form says `enctype="multipart/form-data"`). A submit button's `formaction`, `formmethod`, and `formenctype` override the form's, as in a native post; a button that posts with GET, or to another site, is left to the browser. It removes the widget's own copy of the token from the fields, so the token never reaches the receipt.
|
|
98
|
+
- It follows the answer as a form post would. A redirect is followed; an HTML page replaces the current one; a refusal leaves the page and says why under the widget. Then it resets the widget, because [a token serves one request](#challenging-a-human).
|
|
99
|
+
|
|
100
|
+
The door decides the request as any other arrival: the token is verified with the provider, the outcome is the arrival's `challenge` signal, and the policy for the form's route decides. The site's backend gets the request with `X-Agent-Custody-Receipt`, or never hears of it. A client without JavaScript, or a bot that posts the form directly, sends no token: when the route's policy requires `context.facts.arrival.challenge.outcome == "passed"`, as it should for a protected form, that arrival gets the 403 with the way in.
|
|
101
|
+
|
|
102
|
+
What to get right:
|
|
103
|
+
- **`hostnames`** must name the hosts the page is served on, or a passed token fails.
|
|
104
|
+
- **A form handler that redirects** must answer 303 (or 302) to a URL on the same site. The script follows it as a page load. A redirect to another site fails in `fetch`, because the request carried the challenge header: the door has already relayed the form, so the page says the answer did not arrive and the form may have been sent. A 307 or 308 makes the browser send the POST again with the same token, which the provider refuses as a duplicate.
|
|
105
|
+
- **Not covered, and refused rather than let through:** a form added to the page after the script ran; a form sent from code with `form.submit()`, which fires no submit event; and a form the script skips because its own method is GET or its own action is on another site, which gets no widget, so a button on it with `formmethod="post"` and an action on this site posts with no token. Each posts natively, and the policy refuses it with a bare 403.
|
|
106
|
+
- **A button that posts natively** (GET, or to another site) takes no token with it: the script disables the widget's hidden token fields first, so hCaptcha's live token does not reach another site's body or a query string.
|
|
107
|
+
- **A Content-Security-Policy** must allow the provider's script and frame (`script-src` and `frame-src` for the hosts above), and the script itself (`script-src 'self'` when the door serves the site).
|
|
108
|
+
- **In authz mode** the proxy serves the site, so route `/.well-known/agent-custody-door/form.js` to the door (`location = /.well-known/agent-custody-door/form.js { proxy_pass http://door:8780; }`).
|
|
109
|
+
- **In-process**, the Express middleware serves the script itself; a Next.js site adds a route that returns `guard.formScript()` ([the door in your Node app](door-middleware.md#a-form-protected-by-the-challenge)).
|
|
110
|
+
|
|
111
|
+
The tests run the script in a DOM stand-in against a real door and a stand-in provider. By hand, with Cloudflare's test keys below and a static page, the widget rendered and passed in a browser, the form reached the site with its receipt id, and a POST without the script was refused 403. The script is served with a query string as well (`form.js?v=2`), so a cache-busting habit does not break it. Tutorial: [54-door-form.ts](../examples/54-door-form.ts).
|
|
112
|
+
|
|
83
113
|
### A run against Turnstile's test keys
|
|
84
114
|
|
|
85
115
|
The tests stub `siteverify`. This run calls the real one once. Cloudflare publishes [test keys](https://developers.cloudflare.com/turnstile/troubleshooting/testing/) that need no account: the site key `1x00000000000000000000AA`, the secret `1x0000000000000000000000000000000AA` (validation always succeeds), the secret `2x0000000000000000000000000000000AA` (validation always fails), and the dummy token `XXXX.DUMMY.TOKEN.XXXX`. The test secrets accept only the dummy token. Cloudflare answers a test key with the hostname `example.com`, so the config names that hostname. These secrets are public. A real secret still goes only into the environment, never into the config or a flag.
|
|
@@ -257,7 +287,7 @@ Web Bot Auth is the IETF draft for bots and agents that identify themselves by s
|
|
|
257
287
|
|
|
258
288
|
`agents` lists the signature agents whose directories the door will fetch. `authorities` lists the hosts this door serves. The other fields and their defaults are in [the reference](../../../site/reference/door.md#config).
|
|
259
289
|
|
|
260
|
-
**What the door checks**, in order. The first that fails is the `signatureError
|
|
290
|
+
**What the door checks**, in order. The first that fails is the `signatureError`. For a signature whose `keyid` is a did:key, steps 3 (the `Signature-Agent` part), 4, and 8 do not apply, and step 9 uses the key that the did:key names: see [a did:key signature](#a-did-key-signature).
|
|
261
291
|
|
|
262
292
|
1. A `Signature-Input` member tagged `web-bot-auth` (the first one, when there are several), and a byte sequence under the same label in `Signature`. A signature with another tag is for some other purpose, and the arrival is `invalid` for this one.
|
|
263
293
|
2. `keyid`, `created`, and `expires` are present; `alg`, when present, is `ed25519`. The keyid is the RFC 7638 thumbprint of the agent's Ed25519 key, as the draft requires. The door checks Ed25519 only, the draft's algorithm; RSA-PSS and ECDSA signatures are `invalid` with that reason.
|
|
@@ -428,10 +458,10 @@ A site that already runs nginx or Envoy need not send its traffic through the do
|
|
|
428
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)).
|
|
429
459
|
- 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.
|
|
430
460
|
- Check AP2 mandates.
|
|
431
|
-
- 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. A signature agent must be listed in `agents`; the door does not fetch the directory of an origin it was not told about.
|
|
461
|
+
- 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.
|
|
432
462
|
- Challenge an arrival with a passkey. Turnstile and hCaptcha are the providers; see [challenging a human](#challenging-a-human).
|
|
433
|
-
- Bind a grant to its sender without a signature. A grant presented alone is bearer-grade; under its agent's Web Bot Auth signature it is bound: see [presenting a passport](#what-the-door-knows-about-an-arrival).
|
|
463
|
+
- Bind a grant to its sender without a signature. A grant presented alone is bearer-grade; under its agent's Web Bot Auth signature, or under a signature by the key of its did:key agent, it is bound: see [presenting a passport](#what-the-door-knows-about-an-arrival).
|
|
434
464
|
- 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.
|
|
435
465
|
- 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.
|
|
436
466
|
|
|
437
|
-
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.
|
|
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.
|
package/docs/github-action.md
CHANGED
|
@@ -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.
|
|
23
|
+
- uses: svayatta/agent-custody@<commit sha of the release> # 0.16.11
|
|
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.
|
|
40
|
+
| `version` | the `@agent-custody/receipts` version that `npx` runs | `0.16.11` |
|
|
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/threat-model.md
CHANGED
|
@@ -53,7 +53,7 @@ Each row names the attacker, the move, the defence, and whether the defence is a
|
|
|
53
53
|
| Rewrite a receipt after the fact | The receipt's envelope is signed by the gateway key, which the operator holds, so the signature alone does not stop this. What stops it is the log: the leaf hash of the original envelope is in a tree whose head the log signed, and a rewritten receipt has a different hash with no inclusion proof. | evidence, with a remote log; deployment, with a local log the operator can rewrite |
|
|
54
54
|
| Drop a receipt | The log's tree only grows, and consistency proofs between any two heads show nothing was removed. A receipt the operator never logged never existed as evidence, which is the point of `precommit` for consequential calls: the authorization leaf goes in before the action. [Strict mode](usage.md#strict-mode) does that for every call, with a remote hash-only log and no outbox, and its receipts say so, so a verifier can require it; a modified gateway can still claim strict mode. | evidence for logged receipts; withheld calls for pre-committed tools, and for every call under strict mode |
|
|
55
55
|
| Forge a receipt for an action that never happened | Nothing in the log stops the operator logging a fabricated receipt; the log commits to existence, not truth. What limits it: the upstream's signature over the result when the upstream signs, provider attestations where the provider delivers them, and the principal's signature on the grant. A forged receipt for a signing upstream fails its `upstream` checks. | evidence, where the upstream signs; otherwise the operator's word |
|
|
56
|
-
| Act outside the gateway with the provider's own credentials | Nothing on the gateway's side sees it. `agent-custody completeness` lists the provider's objects with the auditor's own read-only key and reports each one that no verified receipt names; a forged receipt file fails verification and cannot cover for it. | evidence, for a provider that lists its objects (Stripe today) |
|
|
56
|
+
| Act outside the gateway with the provider's own credentials | Nothing on the gateway's side sees it. `agent-custody completeness` lists the provider's objects with the auditor's own read-only key and reports each one that no verified receipt names; a forged receipt file fails verification and cannot cover for it. | evidence, for a provider that lists its objects (Stripe and GitHub today) |
|
|
57
57
|
| Replace the policy and claim a different one decided | The receipt carries the sha256 of the policy text; a verifier with the policy file can check it, and a policy change is a different digest in every later receipt. | evidence |
|
|
58
58
|
| Produce a second, cleaner history | With a remote log, both histories would need heads signed by the log's key at the same size with different roots; the checkpoints host and the witness make that detectable. With a local log, a copy taken earlier by someone else is the only defence. | evidence with a witnessed remote log |
|
|
59
59
|
| Erase what an agent believed | `forget` erases the value and leaves a digest keyed by a forget key held outside the ledger, so the erasure is provable without the value. A forget with `none` leaves nothing and the custody pack says so. | evidence |
|
package/docs/tutorials.md
CHANGED
|
@@ -61,6 +61,11 @@ Suggested reading order is the numbering. Output lands in `examples-out/`, which
|
|
|
61
61
|
| 49 | the door behind stock nginx or Envoy: authz checks instead of relaying | [49-door-authz.ts](../examples/49-door-authz.ts) | the door with `authz: true` answers checks as nginx `auth_request` sends them (`X-Original-Method`, `X-Original-URI`): a catalogue read 200 and an unknown refund 403; a verified agent's refund is committed to the log before the 200; a check that names no original request is refused 400 with no receipt; each receipt verifies and its report says it records the decision, not the origin's answer. `deploy/door/demo.sh` runs the real nginx and Envoy | `src/door.ts`, `src/config.ts` |
|
|
62
62
|
| 50 | the refund pilot in one command: `init refunds`, then `--run` | [50-init-refunds.ts](../examples/50-init-refunds.ts) | keys, a grant, a refund policy and a Stripe gateway config written in one call; a test payment, an over-limit refund refused before Stripe, a refund through the gateway, a retry refused because the gateway finds the first refund, and the receipt verified, against a stand-in Stripe |
|
|
63
63
|
| 52 | the door asks a partner detection engine, and the engine signs its verdict | [52-door-partner-verdict.ts](../examples/52-door-partner-verdict.ts) | a stub engine (`scripts/fake-partner.ts`) signs a verdict for each arrival's receipt and route; a browser's `human` verdict is relayed and a bot's refused by a policy on `context.facts.partner`; the receipt carries the verdict as an attested fact and verifies with the engine's key as an upstream key, and not without it; a verdict replayed from another arrival is refused with 503, and so is an arrival when the engine times out (`onFailure: "deny"`), even on a route the policy alone would allow | `src/door-partner.ts`, `src/door.ts` |
|
|
64
|
+
| 53 | completeness from the provider's side, for GitHub | [53-completeness-github.ts](../examples/53-completeness-github.ts) | two pull requests merged through a wrapped tool and a push made with another token; the auditor lists the repository's activity with a read-only token, matches the two merges to verified receipts, and reports the push as an action with no receipt |
|
|
65
|
+
| 54 | the form protector: one script tag puts the door's challenge in front of a plain HTML form | [54-door-form.ts](../examples/54-door-form.ts) | a static site's contact form behind the door; the door serves the script built from its challenge config, without the secret; a direct post with no token is refused and never reaches the site; a post with a passing token reaches it with the receipt id; both receipts verify |
|
|
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
|
+
| 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
|
+
| 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 |
|
|
64
69
|
|
|
65
70
|
## How policies are defined, in one paragraph
|
|
66
71
|
|
package/docs/verification.md
CHANGED
|
@@ -92,7 +92,7 @@ A refused call's `execution` row carries the reason the receipt records, for exa
|
|
|
92
92
|
| egress relayed only for a checked agent | a connection that was relayed (executed, failed, or error) names an agent whose proxy credential the witness checked (`observed`) | an issuer that relayed for an unidentified agent, or a receipt re-signed to hide who it was |
|
|
93
93
|
| guardian receipt carries a policy decision | an ACS Guardian decides every step by policy | a record-only receipt relabelled as guardian |
|
|
94
94
|
| guardian decided, executed nothing | an allowed step is `withheld` (a Guardian forwards nothing) and a denied one is `denied`; the agent asked, reports the call itself, and is trusted to honor the answer ([the ACS Guardian](acs.md)) | a guardian receipt re-signed to claim the call was executed |
|
|
95
|
-
| delegation signature (principal key) | the embedded grant was signed by a key you trust as a principal | a grant the principal never issued |
|
|
95
|
+
| delegation signature (principal key) | the embedded grant was signed by a key you trust as a principal; on every link of its chain, an agent named by a did:key decodes to an Ed25519 key, and that key is the one in `agentKey` when there is one | a grant the principal never issued, a did:key that names no key, a grant whose did:key agent and `agentKey` are different keys |
|
|
96
96
|
| delegation chain to the principal | only when the grant embeds a parent: every link is signed by the key its parent names, holds no scope its parent lacks, sits inside its parent's window, and names the same principal, up to three delegations deep | a sub-agent given more than its delegator had, a link signed by the wrong key, a chain that never reaches a trusted principal |
|
|
97
97
|
| delegation binds principal and agent | the grant names the same principal and agent the receipt names, and the principal keyid matches | a valid grant for someone else, spliced in |
|
|
98
98
|
| delegation valid at receipt time | the receipt's timestamp is inside the grant's window; a call the gateway refused after the grant ran out passes with a note, since only an executed call must sit inside the window | expired or not-yet-valid authority behind an executed call |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-custody/receipts",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.11",
|
|
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",
|
|
@@ -91,8 +91,10 @@
|
|
|
91
91
|
"@types/node": "26.4.1",
|
|
92
92
|
"@vitest/coverage-v8": "5.0.0",
|
|
93
93
|
"ai": "7.0.93",
|
|
94
|
+
"esbuild": "0.28.2",
|
|
94
95
|
"express": "5.2.1",
|
|
95
96
|
"langchain": "1.5.15",
|
|
97
|
+
"miniflare": "4.20260730.0",
|
|
96
98
|
"tsx": "4.23.13",
|
|
97
99
|
"typescript": "7.0.2",
|
|
98
100
|
"viem": "2.57.4",
|