From 212adbe25a852b5aa10c2b79c13123ca65517797 Mon Sep 17 00:00:00 2001 From: chaodu-agent <274062505+chaodu-agent@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:56:39 -0500 Subject: [PATCH 1/5] design: WebAuthn approval bound to the request (#37) Design note only. Evidence: read issue #37, #5, #31, the muse design on main and PR #29 (e7818ad); measured on a build host in a scratch crate: cargo tree, cargo audit (webauthn-rs 0.6.2: 1 advisory), unsafe grep, crates.io metadata. No code, no build of the workspace. --- docs/design/webauthn-approval.md | 748 +++++++++++++++++++++++++++++++ 1 file changed, 748 insertions(+) create mode 100644 docs/design/webauthn-approval.md diff --git a/docs/design/webauthn-approval.md b/docs/design/webauthn-approval.md new file mode 100644 index 0000000..47dff8b --- /dev/null +++ b/docs/design/webauthn-approval.md @@ -0,0 +1,748 @@ +# WebAuthn approval bound to the held request + +Status: design note, no code. Draft for the standing design review; not final. Issue: +[#37](https://github.com/openabdev/auth-proxy/issues/37). Based on `origin/main` at `3878421`. +Builds on `docs/design/muse-gated-passthrough.md` (sections 3.4 to 3.9, 5.2, open question 7) and on the +stage 2 implementation in draft PR [#29](https://github.com/openabdev/auth-proxy/pull/29), which is **in +review and not merged**. Everything below that names a PR #29 function, type or endpoint describes the +branch head `e7818ad` as read on the day of writing. It may change, so this note depends on the +*behaviour* PR #29 gives (an in-memory hold table, one critical section for the approve transition, a +policy re-check inside it) and lists in section 11 the few places where it needs a change. + +## How claims are labelled + +- **[read]** read in code or docs (the file or URL is named). +- **[M]** measured: run during this work. The tag names what was run. All builds, `cargo tree` and + `cargo audit` runs were on a build host in a scratch crate (`/tmp/wa-scratch`), none on the laptop. +- **[I]** inferred from what was read. +- **[A]** assumed. A risk until someone checks it. Section 12 and the stage 0 spike in section 10 say how. + +Text of the form "the gate does X" is a proposal and carries no tag. + +## 0. What the approver should do today (Basic auth, stage 2 as in review) + +Today the approval page is protected by HTTP Basic auth and a per-page CSRF token [read PR #29 +`approval/auth.rs`, `approval/csrf.rs`]. Until WebAuthn exists: + +1. Keep the approver password in a password manager and use a long random value (the runbook generates + `openssl rand -hex 32`) [read `docs/runbooks/muse-stage2.md` on PR #29]. +2. Open the link from the notification, and read the page before pressing anything: method, route, the + "Sent to" upstream, path, query and body. The digest on the page is not something you can check by eye, + so the page itself is the only review. +3. Reach the approval port only over the private network, from your own devices. +4. Do not tap anything inside the notification itself. It carries a fixed sentence and a link + [read PR #29 `notify.rs`, runbook section 3]. + +Whether iOS Safari offers to save the credentials from an HTTP Basic prompt, and whether autofilling them +is then gated by Face ID or Touch ID: **[A], not verified.** Apple documents Face ID or Touch ID gating +for AutoFill of saved passwords in general +([Meet Face ID and Touch ID for the web](https://developer.apple.com/videos/play/wwdc2020/10670/) covers +WebAuthn, not Basic prompts). I found no Apple page that says Safari saves Basic-auth credentials, and the +community answers disagree +([Ask Different 319953](https://apple.stackexchange.com/questions/319953/how-can-i-have-ios-safari-remember-credentials-for-websites-with-https-basic-a/459875) +says it does not; +[Stack Overflow 26236753](https://stackoverflow.com/questions/26236753/how-to-make-ios-safari-saves-password-for-basic-authentication-website) +says the keyboard offers saved passwords). Try it once on the phone before relying on it. + +Even if it works, **it is not a substitute for request-bound WebAuthn.** A Basic password proves that +someone knows a string. It does not prove a person was present, it can be replayed from anywhere the +header can be sent, and it is not tied to the request on the screen. The rest of this note is about those +three gaps. + +## 1. Problem and non-goal + +**Problem.** PR #29 holds a write until the owner approves it. The notification channel (a self-hosted ntfy +server) is one way: it wakes the phone and opens a link [read issue #37]. The approval itself is a Basic +credential plus a CSRF token. There is no biometric step, and nothing ties the credential's use to the +specific request. The design already accepted that for the pilot and named WebAuthn as the later +replacement [read muse-gated-passthrough.md section 3.6 and open question 7]. + +**Non-goal: no approve button inside a notification, ever.** An ntfy `http` action or a link that approves +on GET is out, for four reasons: + +- A notification can be tapped from a lock screen [A, platform behaviour; issue #37 states it]. +- To approve from a notification the credential has to be carried or implied by it. It would sit on the + ntfy server and on the device, readable by anyone who knows the topic [I]. +- The approver would approve something they have not looked at, which breaks the approve-what-you-see + principle that the whole gate rests on [read muse-gated-passthrough.md section 5.2, row "Canonicalized + request, approval bound to its hash"]. +- A GET that approves can be fired by a link preview or a scanner, with no human at all [I]. + +The notification stays a doorbell: a fixed sentence and a link to the page [read PR #29 `notify.rs`]. + +## 2. Threat model + +### 2.1 What Basic auth plus CSRF does not give + +| Property | Basic + CSRF today | Why | +|---|---|---| +| Biometric presence | no | The browser sends the stored password on its own. Nothing asks a person to be there [I]. | +| Hardware-bound, non-replayable credential | no | The credential is a string. Anyone who has it can build the header. The CSRF token is per page, so it stops a hostile page, not a holder of the password [read `csrf.rs` doc comment]. | +| Binding to the specific request | no | The POST names an entry id and echoes a CSRF token. Nothing the approver signed or typed covers the content [read `approval/mod.rs` `decide`]. | + +### 2.2 What WebAuthn adds + +- **User verification, enforced by the server.** The assertion carries the UV flag. The gate refuses an + assertion without it. The option `userVerification: "required"` is a request to the browser, so it is not + relied on: Apple reports that some Safari-adjacent paths ignore it + ([Apple developer forum 813784](https://developer.apple.com/forums/thread/813784)), and the spec makes + the flag the only thing the server can check [I]. +- **A private key that does not travel.** The password cannot be typed, replayed or autofilled into another + tool. See 2.3 for the limit of this on Apple's synced passkeys. +- **Origin binding.** The browser signs over the origin it is on, so a lookalike page cannot collect a + usable assertion [I, W3C WebAuthn model]. +- **Request binding.** The challenge is derived from the entry id, the canonical request digest, the + upstream authority, the hold expiry and a server nonce (section 4.2). An assertion cannot approve another + entry or a changed request. + +### 2.3 What WebAuthn does NOT add + +- **An unlocked approver device in someone else's hands.** Face ID is skipped when the phone is unlocked and + the attacker passes the biometric or the passcode fallback. Out of scope. +- **A compromised gate host.** The gate holds the real upstream credential and the hold table, and it + verifies the assertion. Whoever controls the process can approve anything [read muse-gated-passthrough.md + section 4.3]. +- **Malware on the phone.** Software that can drive Safari can show a different page than the one the + server sent. WebAuthn proves the key was used with user verification. It does not prove the user read the + page [I]. +- **"Hardware-bound" on Apple devices.** Passkeys in iCloud Keychain are synced across the owner's devices + and recoverable ([Apple, About the security of passkeys](https://support.apple.com/en-in/HT213305)). The + backup-eligible flag is set for them [A, from the WebAuthn flags definition]. So the key is not tied to + one device. A security key (roaming, BE=0) is device-bound. The gate records the flag and the owner picks + a policy (open question 3). +- **Exactly-once.** Unchanged from muse-gated-passthrough.md section 5.1. +- **A malicious server showing different content from what it binds.** The page and the challenge come from + the same gate, which is trusted. A client that computes the challenge itself from what it displays + (section 7.4) closes that for non-browser clients only. + +## 3. Placement and configuration + +- The approval plane stays a separate loopback listener on its own port, with its own router, published to + the phone by `tailscale serve` on a second port [read muse-gated-passthrough.md section 3.6, 4.2; PR #29 + `listener/approval.rs`: loopback bind, 16 connections, 10 s header read]. The agent and the caller path + have no route to it. Nothing here changes that. +- **Relying-party id and origin come from configuration, never from request headers.** `rp_id` is the + private-network TLS host name, for example `approve..ts.net`. `origin` is the exact origin the + phone uses, **including the port** of the second `serve` mapping, for example + `https://approve..ts.net:8446`. The gate compares `clientDataJSON.origin` to that string byte for + byte, so a page on the same host name and another port (for instance the public front) produces an origin + mismatch and is refused [I]. +- `ts.net` is on the public suffix list [M `curl https://publicsuffix.org/list/public_suffix_list.dat` + shows `ts.net` at line 16265], so the rp id must be the full host name and cannot be `ts.net`. That is + what is proposed. +- Secure context: the page is served over HTTPS by the front. [A] Safari on iOS treats a `*.ts.net` page + with a valid certificate as a secure context and offers a platform passkey for that rp id. This is issue + #37's first open question and stage 0 measures it on a real phone. +- The approval plane serves plain HTTP on loopback today [read `listener/approval.rs`], so the TLS name, + the certificate and the port all belong to the front. + +## 4. Protocol + +Naming: *entry* is a held request in PR #29's table, *approver* is the owner, *credential* is a WebAuthn +public key credential enrolled for the approver. + +### 4.1 Registration (enrolment) ceremony + +**Start: the host console, not the web.** An operator on the gate host runs a console command that creates +a one-time enrolment token: 128 random bits from the OS, valid for 10 minutes by default and at most 15. +The command writes `sha256(token)`, the label and the expiry to `enrol/.json` in the state directory +(mode 0600, same owner as the proxy) and prints a URL whose token is in the **fragment** +(`https://:/enroll#t=`). The fragment is not sent to the server, so it does not reach +the front's logs or a `Referer`. The page script reads it and puts it in a POST body. The proxy reads the +`enrol/` directory when an enrolment request arrives (a bounded read: at most 4 files) and deletes the file +on first use or at expiry. No control socket is added to the proxy. The token never goes through ntfy. + +**Browser side.** `navigator.credentials.create` with: + +| Option | Value | Why | +|---|---|---| +| `rp` | `{id: rp_id, name}` from configuration | Pinned. | +| `user.id` | 16 random bytes per enrolment, not stored | Required by the API. Unused because we always pass `allowCredentials`. | +| `pubKeyCredParams` | `[{type: "public-key", alg: -7}]` | ES256 only, section 5. | +| `authenticatorSelection.userVerification` | `required` | Biometric or passcode at creation. | +| `authenticatorSelection.residentKey` | `discouraged` | See below. | +| `attestation` | `none` | See below. | +| `excludeCredentials` | already enrolled ids | Avoids duplicates on the same device. | +| `timeout` | 60 s | | + +**Resident vs non-resident.** The approver is one known person on one gate, so there is nothing to +discover: the gate always knows which credential ids it trusts and passes them in `allowCredentials`. A +non-resident request avoids asking the authenticator to store a user handle and makes the sheet show only +the enrolled credentials. [A] iOS creates a discoverable, synced passkey for a platform authenticator +whatever `residentKey` says (Apple's platform authenticator makes passkeys). The gate does not depend on +either outcome. It does not use discoverable login, and it never accepts an assertion for a credential id +that is not in its store. + +**Attestation `none` vs `direct`.** Request `none` and accept only `fmt: "none"` with an empty `attStmt`. +Apple states that attestation statements are meant for device-bound credentials and that passkeys carry +none ([Apple developer forum 713195](https://developer.apple.com/forums/thread/713195), [forum +713431](https://developer.apple.com/forums/thread/713431)). `direct` would give us nothing from a synced +passkey and would add formats to verify (`packed`, and Apple's own anonymous attestation, `apple`) +[read webauthn-rs-core `attestation.rs`: `verify_apple_anonymous_attestation`, `verify_packed_attestation` +and others]. What attestation would buy, proof of which authenticator model made the key, is not a goal for +a single-owner gate. Issue #37 says Apple authenticators use `none` or `packed`. From the sources above the +formats are `none` and `apple`, not `packed`, and with `none` requested only `none` is returned [A]; stage 0 +records what a real phone returns. + +**Server side, `POST /enroll/finish`.** All of these, in order, first failure refuses with a code: + +1. The enrolment token is present, unexpired and unused (the file exists and the hash matches, compared in + constant time). It is spent when the ceremony *starts*, so a guessed token gets one try. +2. The registration challenge is the one issued for this token: 32 bytes from the OS RNG, single use, 120 s, + in memory. +3. `clientDataJSON`: `type` is `webauthn.create`, `challenge` matches, `origin` equals the configured + origin, `crossOrigin` is absent or false, `topOrigin` is absent. +4. `attestationObject` parses under the strict CBOR subset of section 5.2: `fmt` is `none`, `attStmt` is an + empty map, `authData` is present. +5. `authData`: `rpIdHash` equals `sha256(rp_id)`, UP set, **UV set**, AT set, ED clear, and the credential + id is 16 to 1023 bytes. +6. The credential public key is a COSE EC2 key with `alg` -7, `crv` 1 (P-256), and 32-byte `x` and `y`. +7. **Confirmation assertion.** Before the credential is stored, the page does one `get()` for it over a + fresh enrolment-confirmation challenge, and the gate verifies it with the same code as section 4.2. This + proves the key can sign, that UV works on this device, and that the point is valid, since the verifier + rejects a point that is not on the curve at verification time. Only then is the credential written. + +**What is stored** (and nothing else): credential id, public key, signature counter (the value from the +confirmation assertion), a label the operator typed on the console, and the creation time. One more field +is proposed: the backup-eligible flag, because the policy in open question 3 needs it and because a change +of it later is a signal (section 4.2, check 9). No attestation object, no `authData`, no user handle, no +transports. + +### 4.2 Authentication ceremony (one per held entry) + +**Challenge issuance, `POST /pending//challenge`.** The gate checks the id is 32 lowercase hex and the +entry is `Pending`, then returns request options and a **binding** block: + +``` +{ "publicKey": { "challenge": b64url(32 bytes), "rpId": ..., "allowCredentials": [...], + "userVerification": "required", "timeout": }, + "binding": { "entry": ..., "digest": ..., "upstream": ..., "expires_at": ..., "nonce": ... } } +``` + +**The challenge is derived, not random:** + +``` +challenge = SHA-256( "auth-proxy approve v1\n" + || lp(nonce) || lp(entry_id) || lp(identity) || lp(decision = "approve") + || lp(upstream_authority) || lp(request_digest) || u64_be(hold_expires_at_unix) ) +lp(x) = u64_be(len(x)) || x +``` + +- `nonce`: 32 bytes from the OS RNG, one live nonce per entry. +- `request_digest`: PR #29's credential-blind audit digest, a SHA-256 over a length-prefixed encoding of + method, route, raw path, raw query, every forwarded header (credential values replaced by a marker) and + the body [read PR #29 `hold/digest.rs`]. That is the method, the path as policy matched it and the + held-body digest the issue asks for. It does not cover the upstream or the expiry, so they are separate + fields. +- `upstream_authority`: `scheme://host:port` from the entry's `Upstream` [read PR #29 `hold/entry.rs` + `Upstream::authority`]. This is the "Sent to" row of the page. +- `hold_expires_at_unix`: the hold deadline as wall-clock seconds, **frozen when the entry is admitted**, so + the integer the page shows and the integer bound are the same even if the clock steps afterwards. The + authoritative expiry stays PR #29's monotonic deadline. +- `decision = "approve"`: reserves room for a different domain tag if deny ever uses an assertion. +- The conventions follow what the repo already does: a domain tag with a version, length-prefixed fields as + in the hold digest, a 32-byte OS-RNG nonce, one use, in memory, never logged, as in the hello proof + [read `docs/session-plane.md` "Hello proof"; PR #29 `hold/digest.rs`]. Two differences: WebAuthn signs + with an ECDSA P-256 key held by the authenticator, not the Ed25519 runtime seed, and the nonce store + refuses instead of evicting (below). + +**Idempotent issue, bounded by construction.** A second request for the same entry returns the same live +challenge until it is spent or expires. There is therefore at most one live challenge per entry, so at most +`max_held_total` (32 by default) in the whole gate [read PR #29 `default_limits`], an attacker cannot make +the store grow, and nobody can evict the owner's challenge by asking for more. This is the reason for not +copying the hello store's "evict oldest at 64" rule [read session-plane.md]: eviction there is a way to +flush a victim's nonce. The challenge lives for `min(60 s, remaining hold)` on the monotonic clock, in +memory only. A restart clears it, as it clears the holds. + +**Browser.** The page script receives the options, **recomputes the challenge from the displayed binding +fields** and refuses to call `get()` if it differs from the server's value (this catches a server or +template bug that shows one thing and binds another; it does not defend against a malicious server), then +calls `navigator.credentials.get` on a button tap. + +**Server, `POST /pending//approve` with a WebAuthn body.** The body is capped at 4 KiB and parsed with +unknown fields refused. Verification is a function of (stored credential set, live challenge record, the +entry as it is *now*, configuration) and runs **inside the same critical section** that moves the entry out +of `Pending`: + +``` +table lock held (PR #29: approve_if) + 1. entry is Pending (else: already_decided / expired / superseded / gone ...) + 2. policy re-check: still_held(...) (PR #29: policy generation, route authority, hold grant) + 3. a live challenge record exists for this entry and has not expired + 4. recompute challenge from the entry as it is now + the record's nonce + 5. clientDataJSON: type == "webauthn.get"; challenge == recomputed (constant time); + origin == configured origin; crossOrigin absent or false; topOrigin absent + 6. credential id is in the CURRENT credential set (a revoked one is refused here) + 7. authenticatorData: rpIdHash == sha256(rp_id); UP set; UV set; ED clear + 8. BE flag equals the stored BE flag; BS may not be set while BE is clear + 9. counter policy (below) + 10. ECDSA P-256 / SHA-256 signature over authData || sha256(clientDataJSON) verifies + 11. finish(Approved) and delete the challenge record; the handler is told to forward +table lock released +``` + +Checks 1 and 2 are exactly what PR #29 already does in `Table::approve_if` under the table mutex, and the +verification is added as a second closure in that same section (section 11 lists the interface change). +Nothing is verified "before" and acted on "after": a verified assertion for an entry that is no longer +`Pending`, or whose policy check fails, approves nothing. Step 10 is a pure CPU check in the tens of +microseconds [A, ring's ECDSA verify; measure in stage 1], so holding the mutex for it is acceptable. +Failures at steps 3 to 10 leave the entry `Pending` and bump a failure counter on the challenge record. Five +failures retire the record; the owner's next page load gets a fresh nonce. That costs a spoofer nothing +useful and costs the owner a reload. + +**Counter handling.** Apple's platform authenticators report 0 on every assertion, as the spec allows +[A: stated by [MojoAuth's write-up](https://mojoauth.com/blog/signcount-is-dead-why-passkey-clone-detection-doesnt-work-anymore), +not by Apple; stage 0 measures the phone]. webauthn-rs treats this the same way, running the comparison only +when either value is non-zero [read webauthn-rs-core `core.rs` around line 1175]. The gate's rule: + +| Stored | Presented | Result | +|---|---|---| +| 0 | 0 | accept, audit `counter_zero = true`. Clone detection is unavailable for this credential; the single-use derived challenge is the replay defence. | +| 0 | n > 0 | accept, store n | +| s > 0 | n > s | accept, store n | +| s > 0 | n <= s (including 0) | refuse `counter_regression`: possible clone or replay | + +The stored counter is updated in memory in the critical section and written to disk after the section ends +(no file I/O under the table lock). If the process dies between, the on-disk value lags by one. That cannot +help a replay, because replay is stopped by the challenge, which does not survive a restart either. + +**Replay refusal.** An assertion is useful only against one live challenge record. After success the entry +is `Approved` and the record is gone. A second POST finds the entry decided and gets `already_decided`. +Presented against another entry it fails check 5. After a restart there is no record, so check 3 fails. + +## 5. Library choice + +Requirement: verify ES256 assertions, verify `none` registrations, and build the **derived** challenge. + +### 5.1 Comparison + +| | A. `webauthn-rs` 0.6.2 | B. Minimal in-tree verifier | C. Add nothing (keep Basic) | +|---|---|---|---| +| New dependencies | 4 crates (`webauthn-rs`, `-core`, `-proto`, `webauthn-attestation-ca`), 13.6k lines of source [M `find ... *.rs | wc -l` on the registry copies]. `cargo tree -e normal` lists 168 distinct crate names and versions, **86 names not in `main`'s `Cargo.lock`** (190 crates) [M]. | `ring` made a direct dependency of `ap-proxy`. It is already in the lock at 0.17.14 through reqwest and rustls [read `Cargo.lock`]. Zero new crates. About 600 to 900 lines of new code and a fuzz target. | none | +| Licence | MPL-2.0 for the 4 webauthn crates [M `cargo metadata`]. The repo is MIT [read `Cargo.toml`]. MPL is file-level copyleft, acceptable, but it needs a licence check. | none new | none | +| Audit state | `cargo audit` on the scratch crate: **1 vulnerability, RUSTSEC-2023-0071 (`rsa` Marvin timing side channel) on `rsa 0.10.0-rc.19`**, reached via `crypto-glue`; plus 1 warning, `chrono` unmaintained, which is in the lock through `serde_with` and was not on any `cargo tree` edge [M `cargo audit`, database of 1527 advisories]. The gate would only verify RSA public-key signatures, so the timing attack on private-key operations does not apply [I], but CI would fail until an `ignore` is added. `main`'s own lock: 190 crates, no findings [M `cargo audit -f`]. | `ring` is in `main`'s clean audit. | n/a | +| Maintenance | Last release 0.6.2 on 2026-10-31, earlier 0.5.5 on 2026-04-30 and 0.5.4 on 2025-12-10 [M crates.io API]. Active. About 11M downloads for `-core`. | We own it. | n/a | +| Unsafe code | No `unsafe` block, fn or impl in the four webauthn crates [M grep; the 30 hits for "unsafe" in `core.rs` are the name `new_unsafe_experts_only`]. Dependencies not scanned. It pulls in pre-release RustCrypto crates (`rsa 0.10.0-rc.19`, `kbkdf 0.1.0-rc.1`, `digest 0.11`, `sha2 0.11`). | `ring` has `unsafe` and assembly, as it does today for TLS. Our code needs none. | none | +| Async runtime coupling | None. No `tokio`, `hyper`, `mio` or `openssl` in its tree [M `grep Cargo.lock` of the scratch crate]. It is synchronous and fits behind our handlers. | None. | n/a | +| Duplicate crate versions | Yes: `digest` 0.10 and 0.11, `sha2` 0.10 (ours) and 0.11, `base64` 0.21, 0.22 and 0.23, `rand_core` 0.6 and 0.10, `der` 0.7 and 0.8 [M `cargo tree -d`, merged against `main`'s lock by name]. | none | none | +| Custom (derived) challenge | **Not possible through its public API.** The challenge is generated inside the library (`generate_challenge` is private) and held in its `AuthenticationState` [read `core.rs` lines 228 and 986]. Request binding would be server-side bookkeeping: the gate stores `(entry, digest, state)` and verifies against that. | Yes. | n/a | +| Formats | `none`, `packed`, `fido-u2f`, `apple`, `tpm`, `android-key` [read `core.rs` imports]. Far more than we need. | `none` and ES256 only. | n/a | +| Counter / flag policy | Built in. Counter check only when a value is non-zero, BE/BS checks, rejects possible compromise [read `core.rs`]. | We write it (section 4.2). | n/a | +| Security guarantee | Binding to the request by server bookkeeping. | Binding by signature over the digest. | None of the three gaps in 2.1 close. | + +### 5.2 What the in-tree verifier is, and what it is not + +- **Assertion**: JSON parse of `clientDataJSON` (`serde_json`, already a dependency), a fixed-layout parse + of `authenticatorData` (37 bytes plus optional parts), a SHA-256, and one + `ring::signature::UnparsedPublicKey::new(&ECDSA_P256_SHA256_ASN1, point).verify(msg, sig)`. +- **Registration**: the only CBOR in the system. A strict reader for the shapes of an `attestationObject` + with `fmt: "none"` and the COSE key: definite lengths only, no indefinite items, no tags, maps of at most + 4 entries at the top and 8 in the key, integer keys and text keys, nesting depth at most 4, total input at + most 2 KiB, duplicate keys refused, any trailing byte refused. About 150 lines. +- **Not included**: RSA, EdDSA, any attestation statement format, extensions, discoverable login, and + cross-origin or iframe use. Everything outside the subset is refused, not skipped. +- ES256 is what Apple platform authenticators and common security keys use [A]. + +### 5.3 Recommendation: B, with A as the named alternative + +Recommend **B**, the minimal in-tree verifier, for these reasons: + +1. **It is the only option that gives the derived challenge** the issue asks for, and a signature over the + digest is also evidence an auditor can check later (A's server-side binding is not). +2. **The dependency cost is zero crates and no new advisory.** A adds 86 crate names, duplicates the digest + and hash crates already in the tree, introduces a pre-release RSA crate that `cargo audit` flags today + and a copyleft licence, all to support formats we refuse. +3. **The part of WebAuthn we need is small** once attestation is `none` and the algorithm is fixed: the + assertion path is about ten comparisons and one verify call. The risky part of a hand-written verifier is + attestation and CBOR, and we keep the CBOR subset strict and fuzzed. +4. The authenticity of the library's checks is not what protects the gate. The single-use derived challenge + and the table lock are. + +The risk of B is that we wrote the checks. That is why stage 1 below is a pure-function module with a +vector suite, a differential test against `webauthn-rs`, a fuzz target and the negative matrix. If the owner +prefers code that others also review, **A is acceptable** with these changes: bind by server bookkeeping +(the challenge is random and stored with the entry, digest and expiry, and compared at verify), add an +`ignore` for RUSTSEC-2023-0071 with the reasoning above, accept MPL-2.0, and pin the version. The rest of +this note is unchanged. + +### 5.4 How the dependencies would be vetted + +All on a build host, never on the laptop: + +- `cargo tree -e normal --prefix none | sort -u` and `cargo tree -d`, once on a scratch crate for the + candidate and once on the real workspace after the change, diffed against `main` (done for A above [M]). +- `cargo audit` against a copy of the resulting `Cargo.lock` (installed on a build host, version 0.22.2 [M]). + For B the expected diff to `main`'s lock is a changed direct-dependency line and no new package. +- `cargo deny` is **not installed** on a build host [M `cargo deny --version` returned "no such command"]. Install + it there to check licences and duplicate versions, with a `deny.toml` whose allow-list is MIT, Apache-2.0, + BSD, ISC, and MPL-2.0 only if A is chosen. Not run yet. +- For A, before adoption also read the `core.rs` and `attestation.rs` paths used (registration with `none`, + `finish_passkey_authentication`), check the changelog for security fixes in 0.5.x to 0.6, and confirm the + crate's `cargo vet` or audit status upstream. +- For B, before adoption: confirm `ring`'s supported version policy, confirm that `ring` rejects a point not + on the curve (a unit test with an off-curve point), and fuzz the CBOR and `authenticatorData` parsers + (`fuzz/` already exists [read `fuzz/README.md`]). + +## 6. Page flow on iOS Safari + +### 6.1 The page + +The approver sees the existing entry page [read PR #29 `approval/page.rs`]: identity, method, route, +"Sent to" (the upstream authority), path, query, content type, body size, digest, the escaped body, the +forwarded headers, and the superseded and decided states. Additions for this feature: the hold expiry as +"expires in N s" (rendered from the server's remaining time, then counted down by a monotonic timer in the +page, **never from the phone's clock**), and a small "what you are signing" block with the binding fields +(entry id, digest, upstream, expiry). + +**Two buttons only: Approve and Deny.** Approve is disabled until the options have arrived. + +### 6.2 Behaviour + +| Event | What happens | +|---|---| +| Approve tapped | The page calls `get()`. Safari shows the passkey sheet and Face ID or Touch ID. | +| Biometric cancelled, times out, or the user backs out (`NotAllowedError` in the browser) | Nothing is sent to the server. The page says "Cancelled", re-enables Approve, and keeps the same live challenge. The entry stays pending. | +| No enrolled credential on this device (`allowCredentials` finds none) | The sheet offers another device or a security key, or fails. The page shows "No enrolled credential here". | +| Server refuses the assertion | The page shows the refusal code and the entry state. The entry stays `Pending` unless the code says otherwise (`expired`, `superseded`, `already_decided`, `gone`, `policy_changed`). The owner can retry while the hold lives. | +| Verified | The server approves, the handler forwards, the page shows the result string (`success`, `approved_but_abandoned`, ...) from PR #29's result table. | +| Entry expires while the sheet is open | The assertion arrives and is refused `expired`. Nothing is forwarded. | + +**Deny does not need biometrics.** Recommendation: deny stays cheap, with the existing credential. The +reasoning: deny is the safe direction, it must work from a tired phone in a hurry, and a biometric on it +adds friction without protecting anything. Deny has a cost, since it starts the identity's cooldown +[read muse-gated-passthrough.md section 3.4], so it is not open to anyone. It keeps the Basic credential +plus the per-page CSRF token, which is exactly what PR #29 does. So **Basic stays in every mode as the +low-privilege credential: it can open the plane, view and deny, and in `webauthn` mode it can no longer +approve.** An open question (section 13, 1) covers dropping Basic for viewing. + +### 6.3 Sessions + +No long-lived approver cookie and no session. The approve POST carries its own assertion, which is valid for +one entry, once, for at most 60 s. The gate sets no cookie. The only standing credential is the Basic +header that the browser caches, which can view and deny only. The assertion is the only thing that can +approve, and it dies with the entry. + +### 6.4 Script and CSP + +PR #29 serves pages with **no script** and `default-src 'none'` [read `approval/mod.rs` `harden`, +`approval/page.rs`]. WebAuthn needs script. The change, applied to the approval plane only: + +- One static script, `/static/approve.js`, embedded in the binary and served with its own route, about 100 + lines: base64url helpers, the challenge recomputation, `get()`/`create()`, and `fetch` POST. +- CSP becomes `default-src 'none'; script-src 'self'; connect-src 'self'; frame-ancestors 'none'; + form-action 'self'`, plus `Permissions-Policy: publickey-credentials-get=(self)` [A, header name from the + platform docs]. No inline script and no inline style. `X-Frame-Options`, `Referrer-Policy`, + `Cache-Control: no-store`, `Pragma` and `X-Content-Type-Options` stay as in PR #29. +- The page remains server-rendered with every value escaped. The script does not render request data into + HTML. +- State-changing POSTs also check that `Origin` equals the configured origin, an extra check alongside the + assertion's own origin binding. + +### 6.5 Opening the link from the notification on a locked phone + +Tapping the notification on a locked phone makes iOS unlock first [A]. The link opens in Safari. A GET changes +no state (the CSRF token it mints is the only side effect, and it is bounded [read `csrf.rs`]). The page +does **not** call `get()` on load: it needs a tap, and Safari requires a user gesture for it [A]. So the +sequence is unlock (Face ID), the Basic prompt or autofill, read the page, tap Approve, Face ID again. There +is no path from the lock screen to an approval. The cost is two biometric prompts, which is the price of not +having an approve action in the notification. + +## 7. Approval API stays client-agnostic + +### 7.1 Endpoints (proposed) + +| Endpoint | Purpose | +|---|---| +| `GET /pending`, `GET /pending/` | As in PR #29. The JSON view gains `approval.methods` and the `binding` block. | +| `POST /pending//challenge` | Returns request options plus `binding`. Idempotent per entry. | +| `POST /pending//approve` | Body `{"csrf": ...}` (Basic path, where the mode allows) or `{"webauthn": {...}}`. Answers `{"result": ...}` with the same result names and statuses as PR #29. | +| `POST /pending//deny` | Unchanged. | +| `GET /enroll`, `POST /enroll/begin`, `POST /enroll/finish` | Enrolment, section 4.1. | + +### 7.2 A CLI or native client + +The JSON forms are the browser's `PublicKeyCredentialRequestOptionsJSON` and the assertion JSON, so any +WebAuthn client can use them. A native iOS client would use `ASAuthorizationPlatformPublicKeyCredentialProvider` +with the same rp id. [A] That needs the app associated with the domain (`webcredentials:` entry in an +`apple-app-site-association` file at the rp id host). This is issue #37's last open question and is left +open (section 13, 6). + +### 7.3 Mode and the Basic path + +Section 9. + +### 7.4 Recomputing the challenge + +`binding` carries every input of the challenge hash. A non-browser client can recompute the challenge from +the content it renders itself and refuse to sign if it differs from the server's value. That gives a client +that does not trust the page template an end-to-end approve-what-you-see check. It still trusts the gate for +the content. + +## 8. Storage and configuration + +### 8.1 Credential store + +- **Where.** `approvers.json` in a state directory owned by the proxy user, directory mode 0700 and file + mode 0600. The proxy refuses to start in `webauthn` or `either` mode if the file is group or other + accessible, matching how stage 2 treats secret files [read runbook section 3: notify files must be 0600, + "anything else refuses to start"]. +- **Shape.** `{"version": 1, "credentials": [{"label", "id" (base64url), "pubkey" (standard base64 of the + 65-byte uncompressed point, as the runtime public key is stored in standard base64 [read + session-plane.md]), "counter", "created", "backup_eligible"}]}`. +- **Atomic update.** Write a temp file in the same directory with mode 0600, `fsync`, `rename` over the + target, `fsync` the directory. Keep the previous version as `approvers.json.bak` (mode 0600). The + counter write happens outside the table lock and is skipped if unchanged. +- **Reload.** The proxy compares the file's modification time and length when it issues a challenge and at + every verification, and reloads when they changed. An unreadable or invalid file keeps the last good set + and writes an audit line; at startup it refuses to start (the same posture as an invalid policy [read + runbook section 1]). +- **Backup.** The file is small and contains only public data, so a copy is not secret, but its integrity + matters (8.4). Back it up with the rest of the state directory. + +### 8.2 Revocation and multiple credentials + +- More than one credential is supported (a phone and a spare security key). `allowCredentials` lists all. +- **Revoke** from the host console: remove the entry (`auth-proxy approver revoke