# ABY-2 — HTTP Envelope, Proof, Challenge

Version 0.2.14-draft · Part of the AllowedBy specification set

## 1. Purpose

Defines how a runtime presents a grant (or, when no grant is needed, a passport) on an HTTP request to a service, how it proves possession of its key for that exact request, how the service verifies everything offline, and what the service answers when the proof is missing or insufficient.

Design rule: the runtime provides **two headers** and parses **nothing**. The grant is an opaque string received from the node. The proof is a small JWT the runtime signs.

## 2. Envelope headers

| Header | Value | When |
|---|---|---|
| `Allowed-By` | Either one or more grant JWS (ABY-1), comma-separated, leaf first, root last; or one passport JWS (OAID-3) when the request needs no grant (identity-only, node API calls, the first request of a challenge flow). The JWS `typ` tells them apart. | Every request |
| `AllowedBy-Proof` | The proof JWT (§3) | Every request |
| `AllowedBy-Nonce` | A service-issued nonce (§3.2) | Only on routes where the service requires one |

A request carries exactly one `Allowed-By` value: a grant chain or a passport, never both. Node issuance endpoints are not services and define their own document rules (OAID-2, OAID-3 §4). Header values are ASCII.

**Size budget.** `Allowed-By` and `AllowedBy-Proof` together MUST NOT exceed 8 KiB, and a chain MUST NOT exceed depth 1 (two JWS: a root and one child, ABY-1 §4). Services MUST accept envelopes within that budget and reject larger ones, or more JWS, with `431 envelope_too_large`.

**Why depth 1.** Each grant carries the human's registration (`human.reg`), and a root also carries the WebAuthn assertion, so a root grant is about 3.7 KB and a child about 2.7 KB, with a proof of about 0.6 KB. A root and one child (depth 1) come to about 7.0 KB, within the budget; depth 2 would be about 9.7 KB and depth 3 about 12.4 KB, which no envelope within 8 KiB can carry. A slimmer child (one that does not copy `human` from its parent but refers to it) could make deeper chains fit later, with its own version of this rule.

## 3. The proof

JWS compact, `typ: aby-proof+jwt`, `alg` `EdDSA` or `ES256` (OAID-1 §3.1), `kid` = RFC 7638 thumbprint of the signing key. No `iss`.

```json
{
  "v": 1,
  "htm": "POST",
  "htu": "https://api.example.com/invoices/4711/approve",
  "iat": 1761480000,
  "jti": "b7c1Qm…",
  "dth": "<base64url SHA-256 of the exact Allowed-By header value>",
  "bdh": "<base64url SHA-256 of the content as transmitted>",
  "run": "01J9X…",
  "call": 7
}
```

| Claim | Required | Meaning |
|---|---|---|
| `htm` | yes | HTTP method, uppercase |
| `htu` | yes | The request's public URL **without query and fragment**, normalised per RFC 3986 §6.2.2: lowercase scheme and host, default port removed, percent-encoding normalised |
| `iat` | yes | Issued at. Valid when within `[now − 120 s, now + 60 s]` |
| `jti` | yes | Unique id with at least 96 bits of randomness, base64url (a ULID qualifies). Same definition as for documents (OAID-1 §4.2) |
| `dth` | when `Allowed-By` is present | Document hash: SHA-256 over the full header value, commas included. Omitted on calls without `Allowed-By` (service, node and operator calls to a node); there `bdh` binds the body |
| `bdh` | when a body exists | SHA-256 of the content as transmitted, after content-coding; identical to RFC 9530 `Content-Digest: sha-256`. MUST be absent when there is no body |
| `nonce` | when required | The current `AllowedBy-Nonce` value (§3.2) |
| `run`, `call` | no | Run id and call index for audit |

The proof binds the key named in the document to this method, this URL, this document, this body, this moment. It is the DPoP (RFC 9449) shape with the access-token hash replaced by a document hash and a body hash added.

**Strict comparison.** `htu` is compared byte for byte; the runtime normalises before signing, and an unnormalised `htu` (for example `HTTPS://API.EXAMPLE.COM:443/…`) fails. The verifier normalises only the request path (percent-encoding, dot segments).

**`htu` behind proxies.** A service compares `htu` with its configured `public_origin` plus the request path, normalised the same way. Forwarded headers (`Forwarded`, `X-Forwarded-*`) MUST NOT be trusted unless explicitly configured.

### 3.1 Optional profile: RFC 9421

Services that already deploy HTTP Message Signatures MAY accept, instead of `AllowedBy-Proof`, an RFC 9421 signature in the Web Bot Auth profile:

- `tag="web-bot-auth"`, `keyid` = the thumbprint of the key of §4, `alg` OPTIONAL and, when present, the RFC 9421 registry name matching that key (`ed25519` or `ecdsa-p256-sha256`), `created` checked like `iat`, `nonce` checked like `jti`, `expires` OPTIONAL and enforced when present;
- covered components `"@method" "@target-uri" "allowed-by"` and `"signature-agent"`; `"content-digest"` is REQUIRED when a body exists, and the service recomputes `Content-Digest: sha-256` from the content as transmitted;
- `@target-uri` is built from the service's `public_origin`, the request path and the query; unlike `htu`, it includes the query;
- `(keyid, nonce)` enters the replay set of §3.3;
- `Signature-Agent` is the quoted origin of the issuing node (`"https://node.example.org"`), and names the issuing node, whose key directory is at `/.well-known/http-message-signatures-directory` (OAID-2). AllowedBy verifiers still take the key from the document (§4), never from the directory.

A conforming runtime MUST implement the proof JWT; RFC 9421 is OPTIONAL for both sides.

### 3.2 Optional service nonce

A service MAY require a nonce, on its `irreversible` routes or on any route it chooses. It then returns `AllowedBy-Nonce: <value>` on responses, and rejects a proof without a current `nonce` claim with `401 invalid_signature` carrying a fresh `AllowedBy-Nonce`. The runtime retries once with that nonce, whatever the route's class. Nonce lifetime is the service's choice and at most 300 s. With the RFC 9421 profile (§3.1), whose `nonce` parameter is the signature's own replay nonce, the request carries the service nonce in the `AllowedBy-Nonce` header, and `"allowedby-nonce"` MUST be a covered component; a header the signature does not cover is no nonce.

### 3.3 Replay set

The service rejects any `(kid, jti)` seen in the last 300 s (the `iat` window plus skew). For non-safe methods (RFC 9110: anything but `GET`, `HEAD`, `OPTIONS`), a service with more than one instance MUST use a replay set shared by all instances. Safe methods MAY use a per-instance set. Single-use grants MUST be consumed atomically across instances (§5 step 9).

## 4. Where the key comes from

- With a grant chain: the **leaf** grant's `actor.key` (ABY-1 §2.1). Sub-agents sign with their own key. The proof `kid` MUST equal the leaf's `actor.key.kid`, and the request MUST arrive before the leaf's `actor.exp`.
- With a passport: the passport's `key`.

A service never looks a key up. If the key in the document does not verify the proof, the request is rejected.

## 5. Verification algorithm

There is one verifier (CONF-1). Input: an HTTP request and the service's route map. Output: accept with `(agent URI, human id, level, capabilities)`, or an error, with or without a challenge.

1. **Pick the document.** `Allowed-By` absent: `401 passport_required`, with a challenge when the route (step 5) needs a grant (§6). `typ` of the first JWS is `oaid-passport+jwt` (exactly one JWS) or `aby-grant+jwt` (a chain); anything else or a mix: `400 invalid_request`. Over budget (§2): `431 envelope_too_large`.
2. **Parse the proof.** Absent, malformed, or `typ`, `alg` or `kid` not as in §3: `401 invalid_signature`.
3. **Verify the document.** For a grant chain, every grant in the chain, none skipped:
   - JWS against the node's `countersign` key delegated by a node key pinned in the trust list (OAID-5 §3); `typ`; `iss` equals that node; `exp`; `nbf` (REQUIRED);
   - status bit (Token Status List, OAID-3 §7) of every grant and of the root's `human.reg`, with the class from step 5: for `read`/`write` the list is refreshed at least every 300 s and a stale list is used for at most 3600 s, then `503 status_stale`; for `write-hard`/`irreversible` the list MUST be at most 60 s old, else `503 status_stale`;
   - `audience` lists explicit origins and contains this service's origin; `"*"` is rejected; when it lists more than one origin, `display` MUST equal the rendering of `capabilities` with this service's own templates (AMH-1 §4), else `grant_insufficient`;
   - root (`depth = 0`): `human.reg` is a valid `oaid-human+jwt` from a trusted home node (OAID-7 §4), and `human_sig` passes every WebAuthn check of ABY-1 §3.3 (`type`, `challenge`, `origin` = `https://<human.reg.rp_id>`, `rpIdHash`, UP and UV, signature with `human.reg.key`);
   - each child: `child.parent == parent.gid`, `child.depth == parent.depth + 1`, `depth ≤ 1`, and the child is narrower than its parent in capabilities, constraints, audience and time (ABY-3 §3).

   For a passport: OAID-3 §8. Any failure: `401` and no challenge, with code `untrusted_node` (node not trusted), `expired`, `not_yet_valid`, `revoked`, `status_stale` (`503`), `grant_insufficient` (audience), or `invalid_signature` for every other failure, including `human_sig`, a missing `nbf` and a broken chain link.
4. **Verify the proof.** Signature with the key of §4; `now < actor.exp` of the leaf, else `actor_expired`; `iat` window; `(kid, jti)` unseen (§3.3); `nonce` when required; `htm` equals the method; `htu` equals the normalised public URL; `dth` equals the hash of the header value; `bdh` equals the content hash, or absent when there is no body. Failure: `401 invalid_signature` (`actor_expired`: §6).
5. **Look up the route** in the service's route map: required capability, **class**, level, tier, `authn`, `authority`, and the class's maximum lifetime (ABY-3 §4). The class is always the route map's, never the grant's `class` member.
6. If the route needs no grant: accept with the passport identity.
7. **Passport on a route that needs a grant:** `401 grant_required` with a challenge.
8. **Check sufficiency** against the leaf grant:
   - the required capability matches a leaf capability with the request parameters satisfying its constraints (ABY-3 §3); a constraint the route depends on MUST be present: a route with an `amount_field` needs an `amount` constraint, a resource with parameters needs a `scope`. A capability without it does not satisfy the route (fail closed);
   - `exp − nbf` of every grant ≤ the class maximum (`class_lifetime_exceeded`);
   - for `write-hard` and `irreversible`: the root's `initiator.by == "service"` and `initiator.kid` is one of this service's own `kid`s (`grant_insufficient`);
   - effective level `min(human.level, human.reg level, max_level of the countersigning node, max_level of the home node)` (trust list) ≥ required level;
   - custody tier and `human.reg` `authn` meet the route (`tier_insufficient`);
   - when the route requires `authority`, a valid `authority` countersign covers the request (`authority_required`);
   - when the route sets `qes`, the root carries a valid qualified electronic signature (OAID-7 §10) (`qes_required`);
   - when the route sets `mandate`, or the root carries `acting_for`, the mandate is valid for this human and covers the grant (ORG-1 §6) (`mandate_required`);
   - the stricter tenant settings apply when the resource belongs to a tenant (ORG-1 §3.3);
   - when the route requires a linked human, the pair `(human.reg.iss, human.id)` is linked and authorised for the resource (`human_not_linked`, AMH-1 §7);
   - single-use: `request_digest` equals `SHA-256(JCS({ "htm", "htu", "query", "bdh" }))` of this request (`query` = the raw query string; `query` and `bdh` omitted when absent), and the grant is unconsumed.
9. **Consume and count** atomically: mark a single-use grant consumed; add the call to `count` and to `amount` totals (`per: grant`, `day`, `week`, `month`) kept under the root `gid`; add the amount to any authority rule `budget`, refusing with `403 budget_exceeded` when it would be exceeded (ORG-1 §5.3). When the service itself refuses the request after this step and before serving it (its own dispatch checks), it gives back exactly what this step charged for the request, so the approval stays usable; when it cannot (its store does not answer), the approval stays consumed.
10. **Accept.** Audit: `gid` chain with `rev`, `actor.sub`, `human.id`, level, `run`, `call`, `jti`, time.

Steps 3 and 4 MUST both succeed before any challenge that reveals action-specific information is returned; the step 1 challenge carries only `realm` and `error`.

## 6. Errors and status codes

| Status | Codes | Challenge |
|---|---|---|
| `400` | `invalid_request` | no |
| `401` | `passport_required` | yes when the route needs a grant, with `realm` and `error` only |
| `401` | `invalid_signature`, `untrusted_node` | no |
| `401` | `grant_required`, `grant_insufficient`, `level_insufficient`, `qes_required`, `authority_required`, `mandate_required`, `expired`, `revoked`, `actor_expired`, `class_lifetime_exceeded`, `single_use_consumed` | yes, when the service can create an approval that would succeed; `actor_expired` also means "rebind" (§9) |
| `403` | `capability_denied`, `tier_insufficient`, `human_not_linked`, `budget_exceeded` | no — policy refusals no approval can fix |
| `429` | `rate_limited` | no |
| `431` | `envelope_too_large` | no |
| `503` | `status_stale` | no; `Retry-After` set |

Every error response is `application/problem+json` (RFC 9457, OAID-1 §5).

```
HTTP/1.1 401 Unauthorized
WWW-Authenticate: AllowedBy realm="api.example.com", error="grant_required",
    action="invoices:approve", scope="invoice:4711", class="write-hard",
    level="2", tier="1", code="K7QM",
    approve="https://askmyhuman.org/a/8ZK3V4Q9T2M6R1XJ5WB0YHCDNE",
    poll="https://node.example.org/allowedby/v1/approvals/8ZK3V4Q9T2M6R1XJ5WB0YHCDNE/grant",
    request="8ZK3V4Q9T2M6R1XJ5WB0YHCDNE", expires="2026-10-26T12:15:00Z"
Content-Type: application/problem+json

{
  "type": "https://allowedby.org/errors/grant_required",
  "title": "A human approval is required for this action",
  "action": "invoices:approve",
  "scope": "invoice:4711",
  "class": "write-hard",
  "summary": "Approve invoice 4711, up to 4200.00 EUR",
  "code": "K7QM",
  "level_required": 2,
  "tier_required": 1,
  "single_use": true,
  "request_digest": "<base64url SHA-256(JCS({htm, htu, query, bdh})) expected on retry>",
  "approve_url": "https://askmyhuman.org/a/8ZK3V4Q9T2M6R1XJ5WB0YHCDNE",
  "poll_url": "https://node.example.org/allowedby/v1/approvals/8ZK3V4Q9T2M6R1XJ5WB0YHCDNE/grant",
  "approval_id": "8ZK3V4Q9T2M6R1XJ5WB0YHCDNE",
  "expires": "2026-10-26T12:15:00Z"
}
```

Parameters: `error`, `action`, `scope`, `class`, `level`, `tier`, `amount_field`, `code`, `approve`, `poll`, `request`, `expires`. `amount_field` (also in the problem JSON) is the route's JSON Pointer for amounts, present when the route has one, so that a runtime-initiated approval can carry an `amount` constraint the route will match. `approve`, `poll`, `request`, `code`, `expires` and `summary` are absent when the challenge invites a runtime-initiated approval (§7), since no approval exists yet. The problem JSON carries `status` (RFC 9457) and `single_use`; `request_digest` only when single-use. `summary` is the `display.summary` the node rendered from the service's templates (AMH-1 §4); it never contains secrets or full personal data.

**Scope.** `scope` MUST be exactly the resource the verifier compares in §5 step 8: the route's `resource` with the request's path values, taken from the path normalised as for `htu` (RFC 3986 §6.2.2: unreserved characters decoded, so `%61b` gives `ab`), and it MUST be a valid ABY-3 §2 `scope`. A resource may have several segments (ABY-3 §3): `/` and `:` appear only where the template has them. The service answers `400 invalid_request`, never a challenge, when the path holds a malformed escape (a `%` not followed by two hex digits) or an escape that decodes to a control character (`%00`–`%1F`, `%7F`) or to `/` (`%2F`); when a value of the scope, decoded, is not 1 to 64 of `A-Z a-z 0-9 . _ -` (so never `*`, `**`, a space, `:`, `~`, a sub-delimiter or a non-ASCII character: `a%20b` and `x%C3%A9` are refused); or when the whole `scope` is longer than 256 bytes. An approval of that scope can then always satisfy the route on the same request. A service never re-encodes such a value and never logs it. The scope goes back only to the caller that sent its values.

## 7. Who creates the approval request

- **Service-initiated**: the service calls `POST {approvals}` (AMH-1 §3) at a node from its trust list, passing `sub`, capabilities, `request_digest`, `audience` (exactly its own origin) and, when known, `human_hint` and `human_home`. It returns `approve`, `poll` and `code` in the challenge. **REQUIRED** for `write-hard` and `irreversible`; the grant records it in `initiator` and the verifier checks it (§5 step 8).
- **Runtime-initiated**: allowed only for `read` and `write`. The challenge has no `approve`; the runtime calls `POST {approvals}` at its own node. The service later verifies the grant against the actual request, so the runtime cannot widen what was asked. This is also case 0: the runtime creates the approval before any call, from the service's published vocabulary (ABY-3 §5).

## 8. Runtime behaviour on challenge

1. Read `approve`, or create the approval request (§7). The runtime uses `approve` and `poll` only when they are HTTPS URLs on its own home node (or on a node its operator trusts); it never opens any other link a service sends.
2. Deliver the link, `summary` and `code` verbatim to the human through the operator's channel.
3. Poll `poll` with a proof-signed request (`Allowed-By` = passport + `AllowedBy-Proof`) no more than every 5 seconds, honouring `Retry-After`, until `200` (grant), `410` (denied, expired, revoked), or `expires`.
4. Retry the original request with `Allowed-By` and a fresh proof. For single-use grants the method, URL, query and body MUST be byte-identical.

## 9. Rebind

A tier 0 runtime that restarts, or a runtime whose `actor.exp` approaches, keeps its standing grants by rebinding (ABY-1 §6). It calls `POST {approvals}/grants/{gid}/rebind` with `Allowed-By` = the new passport and a proof signed by the **new** passport's key. The node accepts when:

- the new passport has the same `operator.id` and `runtime.id` and a custody tier not lower, **and**
- the new passport chains to the grant's bound passport through `prev`, **or** the body carries `operator_sig`: a JWS `typ: aby-operator+jwt` over `{ "gid", "sub", "aud": <this node>, "iat", "exp" }` with `exp ≤ iat + 300`, signed by an operator key published in the operator's `https://<domain>/.well-known/oaid-operator` JWKS (OAID-2 §6); `sub` is the new passport;
- the grant is not single-use and has no children.

Operators without a verified domain cannot rebind after a tier 0 restart; they request new approvals.

The node then issues a new **revision**: same `gid`, `rev` incremented, new `jti`, new `actor` and `actor.exp`, its own status index, same `human`, `human_sig`, capabilities and `exp`; and logs it. `actor` (except `actor.operator` and `actor.runtime`), `rev` and `jti` are outside the human-signed core, so `human_sig` stays valid. Earlier revisions are not revoked; they die at their own `actor.exp`. Several replicas MAY each hold their own revision. No human is involved; services see a normal grant.

## 10. Security considerations

- The proof binds the document, the body, the method and the URL to one moment and one nonce. A captured envelope cannot be replayed, re-targeted or given a different body. The query is bound only for single-use grants (§5 step 8); services MUST NOT carry authorisation-relevant parameters in the query of a non-single-use route unless they check them as constraints.
- The proof key is the leaf grant's, bounded by `actor.exp`: a leaked tier 0 key dies with its passport.
- Copying the key into the grant means a compromised node could mint a grant naming any key. `human_sig` over the core, `human.reg` from the home node and the log make this detectable, and trust lists make it revocable.
- Rebinding is bounded by the operator binding, the custody tier and the `prev` chain or operator signature; every revision is logged where the operator's monitor sees it.
- Challenges leak which actions exist. Services MAY answer callers with no valid document with the bare `passport_required` form.

## Change log

Every change to this document adds a row here and increments its version (README, Versioning).

| Version | Date | Change |
|---|---|---|
| 0.2.14-draft | 2026-11-28 | §2, §5 step 3: a chain is at most depth 1 (two JWS), not 3; the size arithmetic behind it (ABY-1 0.2.6). |
| 0.2.13-draft | 2026-11-28 | §3.2: a service MAY require a nonce on any route it chooses, not only on irreversible ones, and the runtime retries once whatever the route's class; with RFC 9421 the nonce is the `AllowedBy-Nonce` header, a covered component. |
| 0.2.12-draft | 2026-11-27 | §5 step 9: a service that refuses the request itself after step 9, before serving it, gives back exactly what the step charged for it; when it cannot, the approval stays consumed. A service's own dispatch checks after the verification no longer burn a single-use approval. |
| 0.2.11-draft | 2026-11-26 | Change-log rows 0.2.7 to 0.2.10 cite CHANGES §26. |
| 0.2.10-draft | 2026-11-26 | §6: the scope is the resource the verifier compares (normalised path values) and a valid ABY-3 scope: a value outside the ABY-3 segment grammar (1 to 64 of `A-Z a-z 0-9 . _ -`), once decoded, is `400 invalid_request`; malformed escapes, control characters, `%2F` and the 256-byte cap as before. (CHANGES §26) |
| 0.2.9-draft | 2026-11-26 | §6: the `summary` sentence (never secrets or full personal data), dropped by 0.2.7, is restored. (CHANGES §26) |
| 0.2.8-draft | 2026-11-26 | §6: the scope rule holds per value: no `/` inside a value (`%2F` refused); the 256 bytes are for the whole scope. (CHANGES §26) |
| 0.2.7-draft | 2026-11-26 | §6: the challenge `scope` is escaped-path characters only, at most 256 bytes, else `400 invalid_request`; never re-encoded, never logged. (CHANGES §26) |
| 0.2.6-draft | 2026-11-08 | Verifiers check `display` against their own templates when several audiences are named, and fail closed on missing constraints; runtimes open only links on their node (CHANGES §23). |
| 0.2.5-draft | 2026-10-29 | Challenge parameter `amount_field` (CHANGES §19). |
| 0.2.4-draft | 2026-10-29 | Mandate check, tenant settings, period amounts and authority budgets in verification; codes `mandate_required`, `budget_exceeded` (CHANGES §18). |
| 0.2.3-draft | 2026-10-28 | Step 8 checks `qes`; `qes_required` challenges (CHANGES §17). |
| 0.2.2-draft | 2026-10-27 | Step 3 error codes named; strict `htu`; RFC 9421 profile details; runtime-initiated challenge omits `expires` (CHANGES §16). |
| 0.2.1-draft | 2026-10-27 | Passport in `Allowed-By`; `initiator` check for write-hard and irreversible; `dth` omitted without `Allowed-By`; rebind rules (CHANGES §15). |
| 0.2.0-draft | 2026-10-27 | One verifier algorithm; `request_digest`; shared replay set; status freshness per class (CHANGES §8). |
