regent-httpsig 0.7.2__py3-none-any.whl → 0.8.0__py3-none-any.whl

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.
@@ -0,0 +1,549 @@
1
+ Metadata-Version: 2.5
2
+ Name: regent-httpsig
3
+ Version: 0.8.0
4
+ Summary: Verify and sign AI agent HTTP traffic in Python — RFC 9421 HTTP Message Signatures: Web Bot Auth (what OpenAI ships) and AAuth.
5
+ Project-URL: Homepage, https://github.com/regent-protocol/regent-httpsig
6
+ Project-URL: Repository, https://github.com/regent-protocol/regent-httpsig
7
+ Project-URL: Issues, https://github.com/regent-protocol/regent-httpsig/issues
8
+ Project-URL: Changelog, https://github.com/regent-protocol/regent-httpsig/blob/main/CHANGELOG.md
9
+ Project-URL: Security policy, https://github.com/regent-protocol/regent-httpsig/blob/main/SECURITY.md
10
+ Author-email: Regent Protocol <info@regentprotocol.org>
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: aauth,agent-identity,ai-agents,bot-detection,ed25519,http-message-signatures,rfc9421,web-bot-auth
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Internet :: WWW/HTTP
20
+ Classifier: Topic :: Security :: Cryptography
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: cryptography>=42
24
+ Requires-Dist: http-message-signatures<2.1,>=2.0.1
25
+ Requires-Dist: httpx>=0.25
26
+ Requires-Dist: typing-extensions>=4.10
27
+ Provides-Extra: aauth
28
+ Requires-Dist: pyjwt>=2.8.0; extra == 'aauth'
29
+ Provides-Extra: fastapi
30
+ Requires-Dist: fastapi>=0.100; extra == 'fastapi'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # regent-httpsig
34
+
35
+ **Verify and sign AI agent HTTP traffic in Python.**
36
+ RFC 9421 · Web Bot Auth · AAuth
37
+
38
+ Some AI agents already sign their HTTP requests with Web Bot Auth: OpenAI says ChatGPT Work's
39
+ Cloud browser signs its outbound requests ([OpenAI][src-openai]), and Google signs a subset of
40
+ Google-Agent requests, as an experiment ([Google][src-google-agent]). On the receiving side,
41
+ Cloudflare validates these signatures for signed agents and verified bots
42
+ ([Cloudflare][src-cloudflare]), AWS WAF Bot Control verifies them for CloudFront distributions
43
+ ([AWS][src-aws]), and Google Cloud Fraud Defense (reCAPTCHA) can verify them
44
+ ([Google Cloud][src-google-cloud]). This library brings both sides to Python: **verify** signed
45
+ agents calling your API, and **sign** your own agent's traffic. (Sources checked on
46
+ 1 December 2026.)
47
+
48
+ [src-openai]: https://help.openai.com/en/articles/11845367-chatgpt-agent-allowlisting
49
+ [src-google-agent]: https://developers.google.com/crawling/docs/crawlers-fetchers/web-bot-auth
50
+ [src-cloudflare]: https://blog.cloudflare.com/signed-agents/
51
+ [src-aws]: https://aws.amazon.com/about-aws/whats-new/2025/11/aws-waf-web-bot-auth-support/
52
+ [src-google-cloud]: https://docs.cloud.google.com/recaptcha/docs/sign-requests-web-bot-auth
53
+
54
+ ```bash
55
+ pip install regent-httpsig
56
+ ```
57
+
58
+ ## What a valid signature proves, and what it does not
59
+
60
+ A `VerifiedSignature` means: someone holding the private key signed **the covered parts** of
61
+ this request, and that key is bound to the named identity — for Web Bot Auth, the key was
62
+ published at the `Signature-Agent` URL when it was fetched over TLS; for AAuth, the named
63
+ issuer's token binds it (`cnf.jwk`), or the pinned server publishes it.
64
+
65
+ It does **not** prove:
66
+
67
+ - **trust** — that the agent or its operator is honest or the one you think; `sig.trusted`
68
+ only reflects your own allow-list;
69
+ - **authorization** — that the agent may do what it asks;
70
+ - **consent** — that a human or an account owner approved this request;
71
+ - **freshness** — that the request is new: a valid signature can be replayed until it expires
72
+ unless you add a [replay guard](#replay) or make the action idempotent;
73
+ - anything about **parts that were not covered**: by default a Web Bot Auth signature only has
74
+ to cover the host, so it says nothing about the method, path or body.
75
+
76
+ ## Verify: know which AI agent is calling — in 5 lines
77
+
78
+ ```python
79
+ from fastapi import FastAPI
80
+ from regent_httpsig import HttpsigVerifier
81
+ from regent_httpsig.fastapi import attach, SignatureDep, VerifiedSignature
82
+
83
+ app = FastAPI()
84
+ attach(app, HttpsigVerifier())
85
+
86
+ @app.post("/v1/orders")
87
+ async def create_order(sig: VerifiedSignature | None = SignatureDep):
88
+ if sig:
89
+ print(sig.scheme) # "web-bot-auth"
90
+ print(sig.agent) # "https://chatgpt.com"
91
+ print(sig.keyid) # RFC 7638 key thumbprint
92
+ ...
93
+ ```
94
+
95
+ `sig.keyid` is the thumbprint of the key that signed, in every scheme. Check `sig.scheme`
96
+ before you treat it as an identity, and key any lookup on `(scheme, keyid)`, never on the
97
+ keyid alone: a Web Bot Auth key, an AAuth agent key and a server key are different identities.
98
+
99
+ No FastAPI? The core has no framework dependencies:
100
+
101
+ ```python
102
+ verifier = HttpsigVerifier()
103
+ sig = await verifier.verify(method, url, headers) # VerifiedSignature | None
104
+ out = await verifier.verify_detailed(method, url, headers, body)
105
+ # VerifiedSignature | VerificationError(code="expired_jwt", …) | None
106
+ ```
107
+
108
+ For a request from ChatGPT's Cloud browser, `sig` prints as (keyid: the thumbprint of the key
109
+ chatgpt.com published on 1 December 2026):
110
+
111
+ ```text
112
+ VerifiedSignature(scheme='web-bot-auth', agent='https://chatgpt.com',
113
+ keyid='ArwjqcCqtA5oxEWkzXGC-To_0A9whHmajCHtfe8I9aY', trusted=False,
114
+ sub=None, label=…,
115
+ claims={'directory': 'https://chatgpt.com/.well-known/http-message-signatures-directory',
116
+ 'jwk': {'kty': 'OKP', 'crv': 'Ed25519',
117
+ 'x': 'P_1c4SX6fCavDcq6FRegWcVvaOKsp_aXHPEN1FcKDIA'}})
118
+ ```
119
+
120
+ `claims["directory"]` is the exact URL the key was fetched from (query included) and
121
+ `claims["jwk"]` the key itself, so you can record where a key came from, not only who it named.
122
+
123
+ Verification is **enrichment by default**: no `Signature` header costs nothing, a bad
124
+ signature yields `None`, and nothing ever raises on untrusted input. `verify_detailed()`
125
+ says *why* with the `Signature-Error` code of draft-hardt-httpbis-signature-key exactly
126
+ as AAuth -11 §11.3.4 assigns it (`invalid_signature`, `invalid_input`, `unsupported_scheme`,
127
+ `unsupported_algorithm`, `invalid_key`, `unknown_key`, `issuer_missing`, `issuer_mismatch`,
128
+ `invalid_jwt`, `expired_jwt`, `revoked_jwt`, `clock_skew`); `error.headers()` is the 401's
129
+ header set and `error.problem()` its problem+json body. Use
130
+ `regent_httpsig.fastapi.RequiredSignatureDep` when a signature must be present — the 401
131
+ carries that header, or `AAuth-Requirement: requirement=agent-token` when nothing was signed.
132
+
133
+ > **Verify against your own public URL, never one built from the client's `Host`.** The
134
+ > signature covers `@authority`, and it binds the request to *your* site only if the URL you
135
+ > verify against names your site. Framework-free: pass `verify()` the URL of your own public
136
+ > origin plus the request path, not one assembled from the `Host` header — otherwise a
137
+ > signature made for another site verifies here when replayed with that site's `Host`.
138
+ > FastAPI: set `HttpsigConfig(public_origins=frozenset({"https://api.example"}))`; the URL is
139
+ > then built from the configured origin that matches `Host` (scheme included), and a signed
140
+ > request whose `Host` is none of them is refused before verification. If one host is listed
141
+ > under both `http://` and `https://`, `X-Forwarded-Proto` decides which, and without that
142
+ > header it is `https://` — never the connection's own scheme, which behind a TLS-terminating
143
+ > proxy is plain http. A client that reaches you directly over plain http (no proxy, no
144
+ > header) with a signature covering `@target-uri` or `@scheme` is then refused; list only the
145
+ > scheme you serve, or have the proxy send `X-Forwarded-Proto`. **Without that
146
+ > setting the FastAPI layer rebuilds the URL from the client's `Host` and
147
+ > `X-Forwarded-Proto`, as 0.7 did**, so the proxy in front must pass only your own names (and
148
+ > forward the scheme — nginx: `proxy_set_header X-Forwarded-Proto $scheme;`). If signatures
149
+ > mysteriously fail to verify in production, check the scheme first.
150
+
151
+ ## Sign: get your agent past bot walls
152
+
153
+ ```python
154
+ from regent_httpsig import EgressSigner
155
+
156
+ signer = EgressSigner(seed=os.environ["AGENT_KEY_SEED"],
157
+ signature_agent="https://myagent.example")
158
+ headers = signer.sign("POST", url, {"content-type": "application/json"})
159
+ resp = httpx.post(url, json=body, headers=headers)
160
+ ```
161
+
162
+ `headers` now carries (values shortened):
163
+
164
+ ```text
165
+ content-type: application/json
166
+ Signature-Agent: "https://myagent.example"
167
+ Signature-Input: sig1=("@method" "@authority" "@path" "signature-agent");created=1796102314;
168
+ keyid="BTd4PmkX…";alg="ed25519";expires=1796102614;tag="web-bot-auth"
169
+ Signature: sig1=:g7Pk5Qc4…:
170
+ ```
171
+
172
+ Generate a key and the ready-to-publish `/.well-known/` files in one command:
173
+
174
+ ```bash
175
+ regent-httpsig keygen --agent https://myagent.example --out ./well-known/
176
+ ```
177
+
178
+ ```text
179
+ # Keep this secret — it IS your agent's identity:
180
+ # keyid (RFC 7638 thumbprint): NXlkuIrk…
181
+ # Wrote ./well-known/http-message-signatures-directory and jwks.json
182
+ # Serve them at https://myagent.example/.well-known/
183
+ AGENT_KEY_SEED=…
184
+ ```
185
+
186
+ Publish the directory at `https://myagent.example/.well-known/http-message-signatures-directory`
187
+ and Web Bot Auth verifiers can fetch your key and verify your agent's signatures. Some also
188
+ ask you to register the agent first (Cloudflare's verified bots and signed agents do).
189
+
190
+ The same key signs as an **AAuth agent** (-11 §11.3.3) — the token in `Signature-Key`,
191
+ the required components covered, `Content-Digest` computed when there is a body:
192
+
193
+ ```python
194
+ headers = signer.sign_aauth("POST", url, {"content-type": "application/json"},
195
+ token=agent_token, body=raw_body)
196
+ ```
197
+
198
+ and a **server** (a PS or AS calling a resource's usage or revocation endpoint, §11.3.2)
199
+ signs under the `jwks_uri` scheme with `ServerSigner(seed=…, server_id="https://ps.example",
200
+ dwk="aauth-person.json")` — publish `.jwks()` at your metadata document's `jwks_uri`.
201
+
202
+ ## What exactly is verified
203
+
204
+ Drafts as checked on the IETF datatracker on 1 December 2026: Web Bot Auth is
205
+ `draft-ietf-webbotauth-httpsig-protocol-01` (29 October 2026), which replaces
206
+ `draft-meunier-web-bot-auth-architecture` (last revision -05, expired 3 September 2026);
207
+ AAuth is `draft-hardt-oauth-aauth-protocol-11` (25 September 2026), with
208
+ `draft-hardt-httpbis-signature-key-09` (13 September 2026) for `Signature-Key` and
209
+ `Signature-Error`, and `draft-hardt-aauth-budgets-00` (28 September 2026) for budgets.
210
+
211
+ | Check | Status |
212
+ |---|---|
213
+ | RFC 9421 Appendix B.2.6 Ed25519 vector (byte-exact) | ✅ in CI |
214
+ | Web Bot Auth -01 Appendix E.2.1 — sf-dictionary `Signature-Agent`, member keyed by the label, covered with `;key=` | ✅ in CI |
215
+ | Web Bot Auth -01 Appendix E.2.2 — legacy sf-string form (what OpenAI's Cloud browser sends) | ✅ in CI |
216
+ | Web Bot Auth architecture -05 A.2.2 — member keyed differently from the label (`;key="agent2"`) | ✅ in CI¹ |
217
+ | Web Bot Auth -01 §5.2 rules: `@authority` (or `@target-uri`) and the `Signature-Agent` member covered, `expires` required with no grace, `created` at most 5 s ahead, attribution only to the covered member, member values resolved directly as JWK Sets, directories answered `200` only | ✅ in CI |
218
+ | Externally generated Web Bot Auth fixtures ([issue #2](https://github.com/regent-protocol/regent-httpsig/issues/2), CC0): valid, tampered `@authority`, expired by 1 s, `created` in the future, unknown keyid, swapped `Signature-Agent`, wrong tag, replay (with a guard) | ✅ in CI |
219
+ | Sign → verify roundtrip (fresh keys, full pipeline) | ✅ in CI |
220
+ | AAuth -11 agent / person / auth tokens (`cnf.jwk` proof of possession, required components, body digest, 60 s `created` window, RS-51 token time, fully-specified algs, Ed25519 + ES256 possession keys) | ✅ in CI |
221
+ | AAuth -11 server scheme (`jwks_uri` with `id`/`dwk`/`kid`, `issuer_mismatch`, key rotation refetch; `verify()` only for pinned servers; `keyid` = thumbprint) | ✅ in CI |
222
+ | Every -11 §11.3.4 Signature-Error code, `revoked_jwt` via the revocation record, RS-52 case-exact ids | ✅ in CI |
223
+ | Key members in canonical base64url only; one RFC 7638 thumbprint per key (RFC 7638 §3.1 example) | ✅ in CI |
224
+ | Replay guard on both paths, keyed on the signature base (an ECDSA signature's twin is still a replay) | ✅ in CI |
225
+ | Signed by [`aauth-signing`](https://github.com/christian-posta/aauth-python-library) (jwt scheme, keyid-less) → verified | ✅² |
226
+ | Tampered request / expired signature / wrong directory key rejected | ✅ in CI |
227
+
228
+ ¹ The signature bytes printed in the -05 A.2.2 example do **not** verify over that draft's
229
+ own signature base (its legacy A.2.3 vector and RFC 9421 B.2.6 both do, so the defect is in
230
+ the example, not the canonicalization). Ed25519 is deterministic, so our test pins the vector
231
+ re-signed with the same RFC test key over the same byte-exact base — reported upstream. The
232
+ -01 dictionary vector (E.2.1) verifies as printed; -01's legacy vector (E.2.2) is the -05 A.2.3
233
+ one unchanged.
234
+
235
+ ² Cross-library interop with `aauth-signing`'s jwt scheme: token layer, `cnf.jwk` proof of
236
+ possession and canonicalization all verify. Its signers correctly omit the optional `keyid`
237
+ parameter — which exposed an unconditional `keyid` read in the underlying RFC 9421 library
238
+ that we now handle. One deviation reported upstream to `aauth-signing`: it emits the
239
+ `Signature` byte sequence as base64url, while RFC 8941 requires standard base64. The
240
+ keyid-less shape is pinned in CI.
241
+
242
+ ## Both dialects, one verifier
243
+
244
+ - **Web Bot Auth** (`draft-ietf-webbotauth-httpsig-protocol-01`, checked 1 December 2026):
245
+ the agent signs with `tag="web-bot-auth"` and names its key directory in `Signature-Agent`.
246
+ Both wire forms are accepted: the sf-dictionary -01 asks signers to send
247
+ (`Signature-Agent: sig1="https://…"`, covered as `"signature-agent";key="sig1"`; Google-Agent
248
+ sends this form) and the legacy bare sf-string OpenAI's Cloud browser sends
249
+ (`"https://chatgpt.com"`). **-01 changes where the keys are**: every member value is now
250
+ a URL fetched directly as the JWK Set. A bare origin, which is what deployed signers send,
251
+ still resolves to `{origin}/.well-known/http-message-signatures-directory`, as in every
252
+ earlier draft; any other https URL is fetched as the JWK Set itself and is the identifier
253
+ (`sig.agent`), without its query. A signature is attributed only to the member it covers.
254
+ -01's defaults are enforced (see [Configuration](#configuration)); stricter ones are yours to set.
255
+ - **AAuth** (`draft-hardt-oauth-aauth-protocol-11`, the current revision on 1 December 2026):
256
+ the agent carries its token in
257
+ `Signature-Key` under the `jwt` scheme — an agent token (`aa-agent+jwt`), a person token
258
+ (`aa-person+jwt`, opt-in via `HttpsigConfig.resource_url`) or an auth token
259
+ (`aa-auth+jwt`, pinned via `trusted_ps`); the issuer's JWKS, discovered through
260
+ `{iss}/.well-known/{dwk}`, verifies the token, the token's `cnf.jwk` verifies the request
261
+ signature. Servers sign under `jwks_uri` (`id`/`dwk`/`kid`); `verify()` accepts that
262
+ scheme only from a server pinned in `trusted_ps` (`allow_unpinned_servers=True` opens
263
+ it), while `verify_server()` is the entry point for usage and revocation endpoints. Install with
264
+ `pip install 'regent-httpsig[aauth]'`. 0.7.0 is the **-11 cut-over** — one dialect, as
265
+ published: fully-specified algorithms only (RFC 9864; `EdDSA` is refused), the required
266
+ covered components, the 60-second `created` window, no tolerance on `exp`, revoked tokens
267
+ named as revoked. `require_fully_specified_algs=False` survives for private test rigs only.
268
+ For a full-protocol AAuth implementation (both roles, all token types) see
269
+ [christian-posta/aauth-python-library](https://github.com/christian-posta/aauth-python-library) —
270
+ this library is the thin relying-party verifier that handles both dialects.
271
+
272
+ ## Budgets: meter a spending envelope (draft-hardt-aauth-budgets)
273
+
274
+ An agent can carry a PS-issued **auth token** (`typ: aa-auth+jwt`) with a
275
+ `budget` claim — a spending envelope it uses offline, no per-call round trip
276
+ to the control plane. The middleware does the whole resource-side checklist:
277
+ verify the token against your pinned PS, atomically reserve → commit →
278
+ release per request, answer with `AAuth-Budget`, and refuse exhausted
279
+ envelopes with a `401` + `AAuth-Requirement` (optionally carrying your signed
280
+ resource token with **one** consumption record — the presented token's
281
+ `{jti, consumed}` — so one agent never learns about a sibling's spending).
282
+ The cap is **per token**: a jti never draws on a sibling's grant; the
283
+ `(iss, sub, aud)` key is only the per-person ledger behind records and usage:
284
+
285
+ ```python
286
+ from regent_httpsig import HttpsigConfig, HttpsigVerifier, InMemoryMeter
287
+ from regent_httpsig.fastapi import BudgetMiddleware
288
+
289
+ app.add_middleware(
290
+ BudgetMiddleware,
291
+ verifier=HttpsigVerifier(HttpsigConfig(
292
+ resource_url="https://api.example",
293
+ trusted_ps={"my-ps": "https://ps.example/jwks.json"},
294
+ )),
295
+ meter=InMemoryMeter(),
296
+ price_fn=lambda request: PRICES.get(request.url.path), # max cost, minor units
297
+ )
298
+ ```
299
+
300
+ The only thing the library cannot do for you is pricing (`price_fn`) — that
301
+ is your domain. Under Implementations in Progress,
302
+ [draft-hardt-aauth-budgets-00 §22.1](https://datatracker.ietf.org/doc/html/draft-hardt-aauth-budgets-00#section-22.1)
303
+ lists Regent Protocol's deployment and names regent-httpsig as its open-source resource/PS
304
+ middleware; the draft's description is of that deployment as of the draft's date, not of
305
+ this release.
306
+
307
+ **The August 20 additions** are covered too:
308
+
309
+ - `insufficient-budget` refusals carry **`required`** — the refused request's
310
+ maximum cost — so the agent lowers its bound and retries instead of guessing.
311
+ - **Revocation** (-11 §11.12): `make_revocation_endpoint(meter, authenticate_ps=…)`
312
+ takes the signed `POST {"jti", "exp"}`, keys the record by the caller's
313
+ verified identity, answers an empty `200` always (no 404) and problem+json
314
+ `invalid_request` / `unsupported_iss`. A revoked token stops spending at
315
+ once, in-flight requests complete, and a later presentation is answered
316
+ `401` + `Signature-Error: error=revoked_jwt` + `AAuth-Requirement:
317
+ requirement=person-token` — no resource token (§11.12.5). Wire
318
+ `HttpsigVerifier(is_revoked=meter.is_revoked)` so the verifier names it first.
319
+ - An **expired** auth token is answered the same way with `expired_jwt`
320
+ (budgets editor's copy, 6 October): nothing is served or metered, and the
321
+ token's final consumption record reaches its issuer through the usage
322
+ endpoint, not on the challenge.
323
+ - **Streaming** responses run in the draft's cost-omitted mode: `reserved` in
324
+ the header, commit when the stream ends (set `request.state.budget_cost`
325
+ mid-stream if you learn the actual), and the agent recovers the exact cost
326
+ from the next response's `remaining`.
327
+ - The **usage endpoint** (§Usage Counters) lets your PS query consumption
328
+ without the agent in the loop — scope counters (`sub`, UTC calendar buckets)
329
+ and per-key `jkts` totals, optionally signed:
330
+
331
+ ```python
332
+ from regent_httpsig import InMemoryMeter, ResponseSigner, make_usage_endpoint
333
+ from regent_httpsig.fastapi import attach, verify_server_request
334
+
335
+ attach(app, verifier) # with HttpsigConfig(public_origins=...)
336
+
337
+ handler = make_usage_endpoint(
338
+ meter,
339
+ authenticate_ps=verify_server_request, # the PS signs as a server, §11.3.2
340
+ unit="USD", decimals=6,
341
+ signer=ResponseSigner(seed=SEED, server_id="https://api.example"), # dwk aauth-resource.json
342
+ )
343
+
344
+ @app.post("/usage")
345
+ async def usage(request: Request):
346
+ return await handler(request)
347
+ ```
348
+
349
+ `verify_server_request` verifies against the same URL as the other FastAPI dependencies
350
+ (`public_origins` when set). Do not build the URL from `request.url` yourself: that is the
351
+ client's `Host` (see the warning under Verify).
352
+
353
+ - `validate_budget_grant(unit, decimals, budget_units)` enforces the resource
354
+ metadata MUSTs before you mint a resource token — the "thousandfold error"
355
+ guard.
356
+
357
+ **Test vectors**: [`vectors/aauth-budgets-vectors.json`](vectors/aauth-budgets-vectors.json) —
358
+ header serializations (including `required` and the cost-omitted streaming
359
+ case), the budget object, consumption records, and a fully worked signed
360
+ usage response with a fixed key, ready for cross-implementation checks.
361
+
362
+ ## Security model (what a naive implementation gets wrong)
363
+
364
+ The verifier fetches key directories from **attacker-nameable origins** — whoever signs a
365
+ request chooses its `Signature-Agent`. regent-httpsig ships with the guard rails on:
366
+
367
+ - **SSRF protection by default**: https-only, every resolved IP must be public (catches
368
+ `169.254.169.254`, loopback, private ranges, DNS names mapping to internal services),
369
+ redirects never followed, anything but `200` refused, responses size-capped.
370
+ - **Bounded caching**: per-instance TTL cache with eviction — a keyid-spam attack can't
371
+ grow memory; failures are negative-cached so a dead origin can't be used to slow you down.
372
+ A failed refetch of a Web Bot Auth directory is not evidence (-01 §6.10): the last good copy
373
+ keeps being served, so an operator's short outage does not revoke its keys — but for at most
374
+ `wba_max_stale_seconds` (default **600 s**) after it went stale, because whoever can make the
375
+ refetch fail (a DoS of the directory host) would otherwise keep a removed key verifying for
376
+ ever. A directory that answers without a key is evidence, and that key stops verifying. AAuth
377
+ issuer and server JWKS are never served stale.
378
+ - **One key, one keyid.** Key members are read only from canonical base64url, and `keyid` is
379
+ the RFC 7638 thumbprint of the key that verified, in every scheme — never a label the
380
+ signer chose. A server (`jwks_uri`) signature names its own `kid`, so `verify()` accepts
381
+ one only from a server you pinned in `trusted_ps`.
382
+ - **Attribution by coverage.** A Web Bot Auth signature is attributed only to the
383
+ `Signature-Agent` member it covers, never to "the first member", and a member with
384
+ parameters or a URL with userinfo is not used.
385
+ - **One header, one value.** The header mapping is normalised once, before anything reads it,
386
+ so the verifier's checks and the RFC 9421 library read the same value. A request in which a
387
+ field the verification depends on (`Signature`, `Signature-Input`, `Signature-Agent`,
388
+ `Signature-Key`, the body fields, `Host`, any covered field) arrives under two spellings, as
389
+ a case-preserving mapping can deliver, is refused.
390
+ - **A valid signature proves key possession — not trustworthiness, authorization, consent or
391
+ freshness** ([above](#what-a-valid-signature-proves-and-what-it-does-not)).
392
+ `VerifiedSignature.trusted` reflects only your configured allow-list; deciding *whether to
393
+ trust* a key is your policy layer's job, and replays are stopped only by a
394
+ [replay guard](#replay) or by your own idempotency.
395
+
396
+ Known sharp edges of the underlying ecosystem, already handled: the upstream
397
+ `http-message-signatures` library cannot resolve RFC 9421 `;key=` dictionary members (we
398
+ provide the component resolver), it looks up header names case-sensitively while ASGI
399
+ frameworks lowercase them (we wrap), and it forgets to declare `typing_extensions` (we
400
+ declare it).
401
+
402
+ ## Configuration
403
+
404
+ ```python
405
+ from regent_httpsig import HttpsigConfig, HttpsigVerifier, InMemoryReplayGuard
406
+
407
+ verifier = HttpsigVerifier(HttpsigConfig(
408
+ trusted_agents=frozenset({"https://chatgpt.com"}),
409
+ max_age_hours=25, # Web Bot Auth: reject signatures created earlier than this
410
+ wba_required_components=("@authority", "signature-agent"), # Web Bot Auth: -01 minimum
411
+ wba_require_expires=True, # Web Bot Auth: -01 makes `expires` a MUST
412
+ wba_max_validity_seconds=None, # Web Bot Auth: cap on expires - created (None = no cap)
413
+ signature_window_seconds=60, # AAuth -11: the `created` window (advertise as signature_window)
414
+ resource_url="https://api.example", # accept person / auth tokens for us
415
+ trusted_ps={"https://ps.example": ""}, # pinned issuers ("" = discover the JWKS)
416
+ cache_ttl=600, # key-directory cache seconds
417
+ ), is_revoked=meter.is_revoked, # optional: name revoked tokens as revoked
418
+ replay_guard=InMemoryReplayGuard()) # optional: refuse a signature seen before (per process)
419
+ ```
420
+
421
+ Pass your app's shared client to reuse its pool: `HttpsigVerifier(http_client=my_async_client)`.
422
+
423
+ **One deliberate deviation from -01:** `max_age_hours` (25) bounds the age of `created` even
424
+ when `expires` is later. -01 sets no upper bound (it recommends `expires` at most 24 hours
425
+ after `created`), but its own test vectors expire in 2124, and -01 §6.9 says a precomputed
426
+ signature must not become a long-lived credential. A signer whose signatures are meant to
427
+ live longer than 25 hours is refused; raise `max_age_hours` to accept it.
428
+
429
+ **Web Bot Auth defaults are the draft's minimum, not a payment profile.** Under -01 a signature
430
+ must cover `@authority` (or `@target-uri`) and its `Signature-Agent` member, and carry
431
+ `expires`; `expires` has no grace and `created` may be at most 5 seconds ahead of your clock.
432
+ Such a signature is valid for any method, path and body sent to your host until it expires
433
+ (-01 §5.2 says so itself). If a verified Web Bot Auth request can move money or change state,
434
+ set at least:
435
+
436
+ ```python
437
+ HttpsigConfig(
438
+ wba_required_components=("@method", "@authority", "@path", "signature-agent",
439
+ "content-digest"), # bind method, path and (when present) body
440
+ wba_max_validity_seconds=300, # at most 5 minutes between created and expires
441
+ )
442
+ ```
443
+
444
+ and pass the request body to `verify()` (the FastAPI layer does), plus a replay guard. Signers
445
+ that cover less are then refused with `invalid_input` and the list of components you require.
446
+ When you pass the body, the body decides whether the request has one (an empty body is no
447
+ body, whatever the framing says). When you do not, the request's own framing decides
448
+ (`Content-Length` above zero, `Transfer-Encoding`, `Content-Digest`); if it then must cover
449
+ `content-digest`, it is refused, because a digest nobody checks binds nothing.
450
+
451
+ ### Replay
452
+
453
+ **A valid signature can be presented again, by anyone who saw it, until it expires** (or, on
454
+ the AAuth path, until its 60-second `created` window closes). The verifier does not stop this
455
+ unless you give it a replay guard, or your application makes the action idempotent itself:
456
+
457
+ ```python
458
+ from regent_httpsig import HttpsigVerifier, InMemoryReplayGuard
459
+
460
+ verifier = HttpsigVerifier(config, replay_guard=InMemoryReplayGuard(max_entries=100_000))
461
+ ```
462
+
463
+ With a guard, the second presentation is refused with `invalid_signature` ("already used") on
464
+ both paths. Verify each request once: a second `verify()` of the same request is a replay too
465
+ (the FastAPI dependencies and `BudgetMiddleware` share one result per request). "The same"
466
+ means the same key and the same signature base (every covered value plus `created`, `expires`
467
+ and any `nonce`), not the same `Signature` bytes — an ECDSA signature has a twin that verifies
468
+ too — and not the label, which intermediaries may change. AAuth has no Signature-Error code
469
+ for replay; `invalid_signature` is the code -11 already gives a signature that verifies but is
470
+ no longer acceptable, and the agent's remedy is the same: sign again.
471
+
472
+ The guard keeps state for signers nobody has vetted, so both what it remembers and what it
473
+ admits are bounded (-01 Appendix C.6):
474
+
475
+ - **Window.** With a guard, a signature is admitted only `replay_window_seconds` (default 300)
476
+ after its `created`, and remembered until `min(expires, created + window + 1)` — never 25
477
+ hours.
478
+ - **Partition.** Each signature is filed under the host that vouches for its key: the Web Bot
479
+ Auth directory's host, the AAuth issuer's, or the AAuth server's — the ASCII name httpx
480
+ connects to (IDNA 2008), lowercase,
481
+ trailing dot stripped, port and scheme ignored. Minting keys, keyids, JWK Set URLs or ports on
482
+ one host stays in one partition, and `InMemoryReplayGuard` lets one partition hold at most
483
+ `max_share` (default 10%) of `max_entries`. A partition over its share is refused; other
484
+ hosts are not.
485
+ - **What remains.** No public-suffix list is consulted, so every subdomain is its own host: a
486
+ signer controlling many subdomains takes one share per subdomain, and ten of them (at the
487
+ default share), each at its cap within one window, can still fill the guard, which then
488
+ refuses everybody new until entries expire (at most 306 s later: the 300-second window, the
489
+ 5 seconds `created` may be ahead of your clock, and one). That takes `max_entries`
490
+ verified signatures per window — a volumetric attack. In the other direction, co-tenants of
491
+ one shared host (object storage, a platform serving per-agent JWK Sets) share one partition,
492
+ and one tenant can exhaust it for the others; so can the agents of one open AAuth issuer.
493
+ The knobs are `max_share` and `max_entries`, and a rate limit in front of the service.
494
+
495
+ `InMemoryReplayGuard` is **per process** and never evicts a live entry: when a partition or the
496
+ whole guard is full it refuses (fail closed). Size it so that `max_entries * max_share` covers
497
+ your busiest legitimate host's verified requests per window. For more than one process,
498
+ implement the `ReplayGuard` protocol over a shared store:
499
+
500
+ ```python
501
+ class ReplayGuard(Protocol):
502
+ async def first_use(self, key: str, *, until: int, partition: str) -> bool: ...
503
+ # True: first use, now remembered until `until`; False: seen before.
504
+ # Raise ReplayGuardFull(partition=...) when it cannot remember; any other
505
+ # exception means "unknown". Both make the verifier refuse.
506
+ ```
507
+
508
+ for example Redis `SET key 1 NX EXAT until` plus a per-partition counter that expires with the
509
+ window.
510
+
511
+ ## Honest limitations
512
+
513
+ - Web Bot Auth and AAuth are **IETF drafts** (RFC 9421 itself is a final standard). We track
514
+ the drafts; breaking draft changes land as minor releases while we're 0.x.
515
+ - Web Bot Auth is **Ed25519 only**. The directories checked on 1 December 2026
516
+ (chatgpt.com, agent.bot.goog) publish Ed25519 keys; -01 allows any registered algorithm
517
+ (its vectors include RSA-PSS), and such signatures are refused here. AAuth
518
+ possession keys may be Ed25519 or P-256 (ES256); RS256 is accepted for issuer keys.
519
+ - On the AAuth path a request with a body **must** cover `content-digest` and
520
+ `content-type` (-11 §11.3.3.1) and the digest is checked against the body you pass —
521
+ so pass it: such a request is refused without it. The FastAPI layer reads the body for you.
522
+ On the Web Bot Auth path -01 requires no body coverage; list `content-digest` in
523
+ `wba_required_components` to require it.
524
+ - Web Bot Auth, not done: only the first `web-bot-auth` signature of a request is verified
525
+ (-01 lets a request carry several); directory response signatures (-01 Appendix B) are not
526
+ checked; known test keys are not refused (-01 §6.8, a SHOULD); directories are cached for a
527
+ fixed `cache_ttl`, not by their `Cache-Control`, and an unknown keyid does not trigger a
528
+ refetch; the directory's media type is not checked.
529
+ - Identifiers are normalised as URIs only (RFC 3986), with no IRI mapping: a path written with
530
+ non-ASCII characters and the same path percent-encoded are two identifiers. `Signature-Agent`
531
+ values are ASCII by construction, so this matters only for URLs you configure yourself
532
+ (`trusted_agents`, `public_origins`): write them percent-encoded.
533
+ - `EgressSigner` still sends the legacy sf-string `Signature-Agent`, which -01 keeps only for
534
+ migration (signers MUST send the dictionary form). It is what OpenAI's Cloud browser sends.
535
+ - The in-memory replay guard is per process (see [Replay](#replay)).
536
+ - Not in 0.8: issuing person/resource tokens, missions, the `202` deferred
537
+ `requirement=auth-token`, federated mode — the PS half of the protocol.
538
+
539
+ ## Related projects
540
+
541
+ [cloudflare/web-bot-auth](https://github.com/cloudflare/web-bot-auth) (TypeScript/Rust) ·
542
+ [christian-posta/aauth-python-library](https://github.com/christian-posta/aauth-python-library)
543
+ (full AAuth protocol) · [pyauth/http-message-signatures](https://github.com/pyauth/http-message-signatures)
544
+ (the RFC 9421 primitive this builds on)
545
+
546
+ ---
547
+
548
+ Built by [Regent Protocol](https://regentprotocol.org) — runtime control and identity for
549
+ AI agents. Apache-2.0.
@@ -0,0 +1,18 @@
1
+ regent_httpsig/__init__.py,sha256=q9rzUg3odl3NtPHlorEtNbsimkG_UNGjAJt7C80y3B4,2344
2
+ regent_httpsig/budget.py,sha256=o4RMS8v9CfDXZlu3Ov_CWB798B-9mc5x4M_I3jj1MGA,21988
3
+ regent_httpsig/cli.py,sha256=WUSLQ2WuEX4E85L2C2EgoUfu5cWpj6MRSG1UVNHpzcw,2005
4
+ regent_httpsig/config.py,sha256=LkM9Nhs4KKcnTb15HR7TSZqCayOaVPgojx_97bv7bdE,8116
5
+ regent_httpsig/fastapi.py,sha256=S6bkcaodXLmGgaC327ibSqAk72hxUKD-5STUyJ6eN1s,24791
6
+ regent_httpsig/jwk.py,sha256=cke86Qjby2DWrs3lJyUEoLWwO6aaKoGK96SnGqvBsJM,5639
7
+ regent_httpsig/netguard.py,sha256=HDj_ArDC6V2lLvrTzSFKQJZJl2nNUilim683K4FIWPw,2608
8
+ regent_httpsig/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ regent_httpsig/replay.py,sha256=dxq5WJtUNRhpyZsyBTrZyuvSN56v7zvwNr653x0jGB8,6861
10
+ regent_httpsig/sfv.py,sha256=8PiYx756gjNtCO4znPdu5A7hoJDJCIVifbcZcg_rhz8,13321
11
+ regent_httpsig/sign.py,sha256=myqUIhWe2y62DGhvyDzTPPlXKfta8EpHskpM0nJzbqk,13180
12
+ regent_httpsig/usage.py,sha256=6qeN7_4a-cNTJOglcgKumqNmag8w7-UF9xTJ1ohI5uU,14818
13
+ regent_httpsig/verify.py,sha256=NPYPp6LUzoLfLbTvl3-uDGLwHVAihaz6MrhjfNmXP_0,56597
14
+ regent_httpsig-0.8.0.dist-info/METADATA,sha256=whe2meJ9URM1xkf_mXq0dX5xRR9DbUhfhGiXJz_xYto,32715
15
+ regent_httpsig-0.8.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
16
+ regent_httpsig-0.8.0.dist-info/entry_points.txt,sha256=SgZdmc27V14IAmwOjbBoCYLsbrALaqdTUHNHLbil2dU,59
17
+ regent_httpsig-0.8.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
18
+ regent_httpsig-0.8.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.32.4
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any