@agent-custody/receipts 0.16.10 → 0.16.12
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 +32 -12
- 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 +14 -0
- package/dist/cli.js +184 -5
- package/dist/completeness.d.ts +11 -2
- package/dist/completeness.js +45 -9
- package/dist/config.d.ts +6 -0
- package/dist/config.js +19 -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 +2 -0
- package/dist/did-key.js +21 -1
- package/dist/door-app.js +1 -1
- package/dist/door-core.d.ts +385 -0
- package/dist/door-core.js +757 -0
- package/dist/door-error-rates.d.ts +102 -0
- package/dist/door-error-rates.js +178 -0
- package/dist/door-form.d.ts +7 -2
- package/dist/door-form.js +52 -4
- package/dist/door-measure.d.ts +153 -0
- package/dist/door-measure.js +325 -0
- package/dist/door-signals.d.ts +414 -0
- package/dist/door-signals.js +555 -0
- package/dist/door-test-set.d.ts +43 -0
- package/dist/door-test-set.js +117 -0
- package/dist/door-worker.d.ts +148 -0
- package/dist/door-worker.js +283 -0
- package/dist/door.d.ts +11 -293
- package/dist/door.js +45 -755
- 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 +11 -2
- package/dist/index.js +6 -1
- package/dist/issue.d.ts +2 -16
- package/dist/issue.js +2 -12
- package/dist/lock.d.ts +5 -0
- package/dist/lock.js +1 -1
- 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 +44 -5
- package/docs/console.md +11 -4
- package/docs/door-error-rates.md +490 -0
- package/docs/door-languages.md +3 -1
- package/docs/door-middleware.md +6 -1
- package/docs/door-quickstart.md +53 -17
- package/docs/door-signals.md +117 -7
- package/docs/door-worker.md +94 -0
- package/docs/door.md +41 -12
- package/docs/github-action.md +2 -2
- package/docs/tutorials.md +6 -0
- package/docs/verification.md +1 -1
- package/package.json +4 -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.12
|
|
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.12 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; 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` is `verified` without any proof that the sender holds the key: it is bearer-grade like any grant
|
|
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 |
|
|
@@ -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.
|
|
@@ -57,7 +121,7 @@ when { context.facts.arrival.class == "verified" };
|
|
|
57
121
|
|
|
58
122
|
`agent-custody check` warns about a permit that names an agent without that condition.
|
|
59
123
|
|
|
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:
|
|
124
|
+
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
125
|
|
|
62
126
|
```cedar
|
|
63
127
|
permit(principal == Agent::"https://crawler.example", action == Action::"api", resource)
|
|
@@ -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
|
|
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
|
|
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.
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
| 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 |
|
|
23
|
+
|
|
24
|
+
## What reaches the policy
|
|
25
|
+
|
|
26
|
+
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.
|
|
27
|
+
|
|
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`.
|
|
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
|
+
|
|
40
|
+
## When R2 or the log is unavailable
|
|
41
|
+
|
|
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.
|
|
43
|
+
|
|
44
|
+
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.
|
|
45
|
+
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
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.
|
|
49
|
+
|
|
50
|
+
## Limits
|
|
51
|
+
|
|
52
|
+
- **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.
|
|
53
|
+
- **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.
|
|
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.
|
|
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.
|
|
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.
|
|
58
|
+
|
|
59
|
+
## Web Bot Auth nonces
|
|
60
|
+
|
|
61
|
+
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.
|
|
62
|
+
|
|
63
|
+
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.
|
|
64
|
+
|
|
65
|
+
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.
|
|
66
|
+
|
|
67
|
+
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.
|
|
68
|
+
|
|
69
|
+
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.
|
|
70
|
+
|
|
71
|
+
## The signing key
|
|
72
|
+
|
|
73
|
+
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.
|
|
74
|
+
|
|
75
|
+
## What was checked, and how
|
|
76
|
+
|
|
77
|
+
- `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:
|
|
78
|
+
- an unknown arrival on a protected route is refused and never reaches the origin;
|
|
79
|
+
- a verified Web Bot Auth arrival is relayed and its receipt verifies;
|
|
80
|
+
- a forged signature, or the same signature twice, is not verified;
|
|
81
|
+
- 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;
|
|
82
|
+
- a Worker whose nonce object fails gives `unavailable`, not `verified`;
|
|
83
|
+
- a grant is checked at the edge;
|
|
84
|
+
- a precommit request is not relayed when the log is down;
|
|
85
|
+
- a safe request's receipt goes to the outbox and the cron appends it;
|
|
86
|
+
- the Bot Management fact is recorded;
|
|
87
|
+
- the Worker's Ed25519 signature is byte for byte the one Node makes over the same bytes;
|
|
88
|
+
- `agent-custody verify` accepts a Worker receipt;
|
|
89
|
+
- a config that names a file is refused with nothing relayed.
|
|
90
|
+
- `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.
|
|
91
|
+
- `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.
|
|
92
|
+
- [56-door-worker.ts](../examples/56-door-worker.ts) is the same run as a tutorial.
|
|
93
|
+
|
|
94
|
+
A deployment to Cloudflare itself, with the receipts it produced, is not recorded here yet.
|