Cryptographic Capability Attenuation · Browser ↔ Edge Worker

Passkey & WebCrypto Attenuated Capabilities

Delegate narrow, short-lived tool authority from the browser without exposing static API keys or ambient cookies. Every capability proof carries signed scopes, an origin binding, a hard USD spend ceiling, a replay nonce, and a short TTL enforced by an edge WebCrypto verifier and SQLite Durable Object ledger (DelegationLedger).

Hypothesis

Non-extractable WebCrypto ECDSA P-256 keys combined with WebAuthn Level 3 prf confirmation and Durable Object spend ledgers enforce verifiable per-action scope, TTL, replay nonce, and cumulative dollar caps without exposing long-lived account secrets.

Confirm vs. Falsify

Confirm: dollar-cap overflow, nonce replay, payload tampering, and out-of-scope calls reject in DelegationLedger while valid attenuated tokens succeed. Falsify: key derivation or passkey prompt latency (measured below) creates UX friction pushing developers back to ambient OAuth.

What to try first

Run Try 1 (Expect 200) to mint a calendar:read proof and call /read-calendar, then Try 2 (Expect 403) for scope escalation and spend overflow, and Try 3 (Expect 401) for 1-byte tamper and expired TTL.

1. Browser Key Boundary & Delegation Mode

WebAuthn Level 3 PRF Extension

The W3C WebAuthn PRF extension requests a deterministic pseudo-random evaluation from a platform or roaming authenticator during user verification. Hardware Passkey mode executes a live navigator.credentials.create() or get() call with extensions: { prf: { eval: { first } } } and binds the returned credential ID and salt metadata into the signed ECDSA P-256 capability claims.

Secure Context Probing...
SubtleCrypto P-256 Probing...
PublicKeyCredential Probing...
Platform Authenticator Probing...
WebAuthn PRF Capability Probing...
Session: — Key: not minted Edge JWK: unregistered Passkey PRF: idle Latency: —

3 Things To Try

1. Mint Read-Only Token & Read Calendar

Mints a token scoped strictly to calendar:read with a $1.00 spend cap and 60s TTL, then calls POST /api/protected/read-calendar.

2. Escalate Scope & Overflow Spend Cap

Calls /send-email without email:send (403 insufficient_scope), then mints a $5.00 cap token and requests $25.00 on /transfer-funds (403 spend_cap_exceeded).

3. Tamper Payload Byte & Expired TTL

Mutates 1 byte inside the signed base64url payload (401 invalid_signature) and sends an already-expired TTL token (401 token_expired).

2. Policy Attenuator

TTL: none
Allowed Tool Scopes
$0.00 / call
$0.50 / call
variable $amount
No active capability token minted yet. $0.00 remaining
Ready. Click Try 1 above or mint a custom attenuated token to invoke protected edge routes.

3. Protected Edge Endpoints & Probes

POST /api/protected/read-calendar Requires scope calendar:read · Cost $0.00
POST /api/protected/send-email Requires scope email:send · Cost $0.50
POST /api/protected/transfer-funds Requires scope payments:transfer · Cumulative cap enforced

Failure Mode & Attack Simulations

4. HTTP Wire & Edge Ledger Inspector

Signed Cap Token & Live HTTP Wire Trace No request sent yet

Authorization Header (Wire Proof)

Authorization: Cap <mint a token to inspect compact base64url proof>

Decoded Capability Claims (Payload)

{}

Last HTTP Request & Edge Verification Response

{}

Ordered Verification Checks

  • Awaiting capability verification...
Registered Public JWK & Key Material Boundary ECDSA P-256 · Public Only

Public JWK Stored in Edge Durable Object (Private parameter d never leaves browser)

{}
Edge Durable Object SQLite Ledger (GET /api/ledger/:sessionId) 0 events
Time Endpoint Scope Spend Decision Reason Remaining
No edge ledger entries recorded for this session yet.

Raw Ledger Snapshot JSON

{}

Architecture & Trust Boundary

1. The Problem

Ambient OAuth cookies and static bearer keys carry full account authority on every request. When an automated tool pipeline calls an API, the server cannot distinguish whether the user authorized a $0 calendar read or an unbounded funds transfer.

2. The Goal

Attenuate authority per task before execution: bind exact tool scopes, a maximum dollar spend cap, the target origin, and an expiration timestamp into a compact cryptographic proof verified independently of ambient browser state.

3. How It Works

Generate a non-extractable ECDSA P-256 keypair inside crypto.subtle (optionally confirmed by a WebAuthn Level 3 PRF passkey prompt), register the public JWK at the edge, and sign Cap <payload>.<sig> tokens checked against signature, TTL, origin, scope, nonce, and cumulative spend.

Passkey and WebCrypto capability delegation runtime boundary Flow from Browser non-extractable P-256 key and optional WebAuthn PRF confirmation to attenuated Cap token, Cloudflare Worker WebCrypto verifier and SQLite DelegationLedger, and capability-gated protected endpoints. BROWSER SANDBOX ECDSA P-256 Keypair extractable: false WebAuthn L3 + PRF optional hardware gate ATTENUATED CAP TOKEN Authorization: Cap <b64>.<sig> scopes: ["calendar:read"] maxSpendUsd: 5.00 · ttl: 60s origin + nonce + keyId EDGE WORKER VERIFIER 1. crypto.subtle.verify(P-256) 2. TTL & Origin Match 3. Scope & Revocation Check DelegationLedger DO SQLite spend & nonces GATED ROUTES /read-calendar $0 /send-email $0.50 /transfer-funds $n Private key material never leaves the browser. Only the public JWK (x, y) is registered at /api/delegate/register.
Figure 1: Signing keys remain non-extractable in browser WebCrypto memory while the Cloudflare Worker verifies every request against registered public JWKs and per-session SQLite spend/nonce state.
How This Is Set Up · Cryptographic Contract

Code Matching the Live App

Mint short-lived ECDSA P-256 capability tokens in the browser via non-extractable crypto.subtle keys and WebAuthn Level 3 PRF confirmation, then enforce scope, origin, nonce uniqueness, and cumulative spend ceilings in the DelegationLedger SQLite Durable Object.

Ambient credentials (unbounded authority)
// Long-lived Bearer secret or ambient cookie grants unbounded scope and spend
const headers = {
  Authorization: `Bearer ${process.env.SERVICE_API_KEY}`,
  "Content-Type": "application/json",
};

// Downstream endpoint accepts the static secret with no per-call budget ceiling
await fetch("/api/protected/transfer-funds", {
  method: "POST",
  credentials: "include", // Ambient cookies attach automatically on requests
  headers,
  body: JSON.stringify({ amount: 250, destination: "acct_vendor" }),
});
Attenuated P-256 capability proof
// public/lib/webcrypto-cap.js + public/app.js — hardware confirmation + scoped P-256 proof
const prf = await runWebAuthnPrfConfirmation({ rpId: location.hostname, sessionId });
const { privateKey, publicKey } = await generateSessionKeyPair(); // extractable = false
await fetch("/api/delegate/register", {
  method: "POST",
  headers: { "Content-Type": "application/json", "X-Session-Id": sessionId },
  body: JSON.stringify({ sessionId, keyId, publicKeyJwk: await exportPublicJwk(publicKey), delegationMode: "webauthn-prf-bound", prfCredentialId: prf.credentialId }),
});
const token = await signCapabilityToken({
  tokenId, keyId, issuer: `session:${sessionId}`, origin: location.origin,
  scopes: ["payments:transfer"], maxSpendUsd: 25, spentBefore: 0, iat, exp: iat + 60, nonce,
  delegationMode: "webauthn-prf-bound", prfCredentialId: prf.credentialId,
}, privateKey);
await fetch("/api/protected/transfer-funds", {
  method: "POST",
  headers: { "Content-Type": "application/json", Authorization: `Cap ${token}`, "X-Request-Nonce": reqNonce, "X-Session-Id": sessionId },
  body: JSON.stringify({ amount: 12.5 }),
});
Complete Page Setup: HTML Markup, Claims Schema & Durable Object Wiring

End-to-end wiring from the policy form in public/index.html, the CapabilityClaims schema in src/capability.ts, WebCrypto/PRF minting in public/app.js (using public/lib/webcrypto-cap.js), and SQLite DelegationLedger verification in src/worker.ts.

<!-- 1. Page HTML Setup (public/index.html) -->
<input type="radio" name="delegation-mode" value="webauthn-prf-bound">
<button type="button" id="btn-passkey-gate">Confirm Passkey + PRF Now</button>
<form id="mint-form">
  <input type="checkbox" id="scope-calendar" name="scope" value="calendar:read" checked>
  <input type="checkbox" id="scope-email" name="scope" value="email:send">
  <input type="checkbox" id="scope-payments" name="scope" value="payments:transfer">
  <input type="number" id="input-max-spend" step="0.50" value="5.00" required>
  <input type="number" id="input-ttl" step="1" value="60" required>
  <button type="submit" id="btn-mint">Register Key &amp; Mint Cap Token</button>
</form>
<script type="module" src="/app.js"></script>

// 2. Concrete Capability Claims Schema (src/capability.ts)
const claims = {
  tokenId: `cap_${crypto.randomUUID().slice(0, 12)}`,
  keyId: state.keyId,
  issuer: `session:${state.sessionId}`,
  origin: window.location.origin,
  scopes: ["calendar:read", "email:send", "payments:transfer"],
  maxSpendUsd: 5.00,
  spentBefore: 0,
  iat: nowSec,
  exp: nowSec + 60,
  nonce: `n_${nonceHex}`,
  delegationMode: "webauthn-prf-bound",
  prfCredentialId: prfResult.credentialId,
  prfSaltHex: prfResult.prfSaltHex,
};

// 3. Page Bootstrap & DelegationLedger SQLite Enforcement (public/app.js + src/worker.ts)
import { generateSessionKeyPair, exportPublicJwk, runWebAuthnPrfConfirmation, signCapabilityToken } from "/lib/webcrypto-cap.js";
const prfResult = await runWebAuthnPrfConfirmation({ rpId: window.location.hostname, sessionId: state.sessionId });
state.keyPair = await generateSessionKeyPair(); // ECDSA P-256, extractable: false
state.publicKeyJwk = await exportPublicJwk(state.keyPair.publicKey);
await fetch("/api/delegate/register", {
  method: "POST",
  headers: { "Content-Type": "application/json", "X-Session-Id": state.sessionId },
  body: JSON.stringify({ sessionId: state.sessionId, keyId: state.keyId, publicKeyJwk: state.publicKeyJwk, delegationMode: state.delegationMode, prfCredentialId: prfResult.credentialId }),
});
const tokenString = await signCapabilityToken(claims, state.keyPair.privateKey);
await fetch("/api/protected/transfer-funds", {
  method: "POST",
  headers: { "Content-Type": "application/json", Authorization: `Cap ${tokenString}`, "X-Request-Nonce": requestNonce, "X-Session-Id": state.sessionId },
  body: JSON.stringify({ amount: 2.00 }),
});
Edge Verification & Atomic SQLite Spend Ledger
// src/capability.ts + src/worker.ts — verify P-256 signature before trusting claims, then debit DO SQLite
const result = await verifyCapabilityToken({
  tokenString, publicKeyJwk, requiredScope, requestedSpendUsd, expectedOrigin, cumulativeSpentUsd: priorSpendSnapshot,
});
// Inside DelegationLedger.verifyAndRecord() — atomic SQLite write inside Durable Object
this.ctx.storage.sql.exec("INSERT INTO used_request_nonces (nonce, token_id, created_at) VALUES (?, ?, ?)", requestNonce, tokenId, now);
this.ctx.storage.sql.exec(
  "INSERT INTO token_spend (token_id, spent_usd, max_spend_usd, revoked, updated_at) VALUES (?, ?, ?, 0, ?) " +
  "ON CONFLICT(token_id) DO UPDATE SET spent_usd = excluded.spent_usd, updated_at = excluded.updated_at",
  tokenId, nextSpent, claims.maxSpendUsd, now,
);
What disappears

Static bearer API keys shared across automated pipelines and ambient session cookies that authorize unconstrained mutations on an origin.

What becomes explicit

Per-token origin binding, scope lists (calendar:read, email:send, payments:transfer), strict exp TTLs, single-use X-Request-Nonce checks, and atomic SQLite spend ceilings (token_spend).

Platform gaps remaining

WebAuthn Level 3 prf extension availability varies across authenticators and OS keychains, and non-extractable browser keys still require registering the public JWK in the edge ledger before enforcement.