Epoch: loading… Worker CSP: Checking… Keys: Not minted Canary Leaks: 0

Delegated Authority · Zero-Key Narrow MCP Gateway

Custodian Narrow MCP Gateway

Giving an automated tool a raw API key—or a wide proxy that can call any URL—turns one bad prompt into full account compromise. This gateway hides upstream credentials inside a Cloudflare Durable Object SQLite ledger behind a narrow 4-tool Model Context Protocol (MCP) front door, requires two separate SubtleCrypto ECDSA P-256 proofs (human approval + per-call agent signature), and checks its browser Worker's securitypolicyviolation policy before accepting keys.

Why this matters

Connecting an agent straight to wide REST catalogs or static API keys floods its context with dozens of schemas and lets prompt injection redirect requests or leak secrets in tool output.

What this opens up

Zero-key narrow MCP gateways let browser-hosted agents discover and run fixed, schema-checked operations—with human-approved call budgets, instant epoch revocation, single-use nonces, and zero upstream credentials in the client.

How the tests work

Mint two separate P-256 keys and enroll a delegation, run a valid fixed MCP operation (200), then launch all 6 live red-team attacks—URL injection, replay, 1-byte tamper, revoked epoch, key collapse, and permissive Worker CSP—while scanning every byte for canary leaks.

3 Things To Try

Follow these three steps in order to create distinct human and agent signing keys, execute one allowed MCP operation, and attack the gateway with six live exploits.

1. Create Dual Keys & Approve a Grant

Generates two non-extractable browser signing keys (one for human approval, one for the agent session), verifies the Worker's locked CSP, and records the signed grant in the edge SQLite ledger.

2. Run One Approved MCP Operation

Signs the exact operation arguments inside the locked browser Worker and sends invoke_operation to POST /mcp, where the edge server attaches UPSTREAM_CANARY_TOKEN privately.

3. Launch All 6 Exploits & Leak Scan

Runs URL injection, nonce replay, 1-byte argument tampering, post-revocation calls, single-key collapse, and a permissive Worker CSP probe—then checks every byte for secret leaks.

6 Live Red-Team Attacks & Secret Leak Scanner

Each button sends a real signed exploit to the Durable Object ledger (CustodianLedger) or tests browser Worker isolation, then scans every response and audit row for UPSTREAM_CANARY_TOKEN.

1. Arbitrary URL / Header Injection

Idle

Tries to smuggle custom url and headers.Authorization fields into invoke_operation. Expected: blocked with 403 ARBITRARY_TARGET_FORBIDDEN.

2. Nonce Replay Attack

Idle

Re-sends an already accepted agentProof and one-time nonce verbatim against SQLite consumed_nonces. Expected: blocked with 409 NONCE_REPLAYED.

3. 1-Byte Argument Tamper

Idle

Signs {"repo":"aifocus","limit":2} then changes one byte (2 → 3) after signing. Expected: blocked with 401 PROOF_DIGEST_MISMATCH.

4. Call After Instant Revocation

Idle

Captures a valid proof, increments the ledger's global revocationEpoch, and submits the stale proof. Expected: blocked with 401 EPOCH_REVOKED.

5. Single-Key Collapse Attack

Idle

Submits the same P-256 key for both human approval and agent signing (agentPublicJwk === humanPublicJwk). Expected: blocked with 403 KEY_COLLAPSE_FORBIDDEN.

6. Permissive Worker CSP Check

Idle

Compares the locked Worker (fit) against an unrestricted Worker (unfit that refuses key admission) and scans every trace for leaks.

Live Attack & Rejection Trace

Run any attack button above to inspect live HTTP/MCP rejections and DO SQLite receipts.

Automated Canary Leak Scanner

Scanner Verdict CANARY_CLEAN (0 leaks)
DO Canary Fingerprint loading…
Samples Scanned 0 client / 0 server
Bytes Inspected 0 B
Patterns Checked exact, base64, suffix, regex
Canary scan results appear here after any attack or manual scan.

Dual P-256 Key Custody & Delegation Enrollment

Browser WebCrypto non-extractable keys enrolled in DO SQLite CustodianLedger

HumanApprovalKey (Delegator) Not generated ECDSA P-256 · extractable: false
AgentSessionKey (Possession) Not generated ECDSA P-256 · extractable: false

Browser Worker CSP Self-Check

Dedicated Worker verifies securitypolicyviolation.originalPolicy before holding AgentSessionKey

Running initial CSP self-check in /workers/secret-custodian.js…

Narrow 4-Tool MCP Gateway Console

Live Streamable HTTP POST /mcp (2025-03-26) — strictly 4 fixed tools, zero generic proxy

No MCP call yet POST /mcp
Select a tool above and click "Execute MCP Tool Call" to inspect live JSON-RPC 2.0 responses.

Wire, Proof Envelope & DO SQLite Ledger Inspector

DO SQLite loading…

Inspect every allow/deny audit row stored in SQLite, the raw human and agent P-256 proof envelopes, and the live JSON-RPC HTTP wire log.

1. Durable Object SQLite Audit Log & Active Delegations
0 receipts in CustodianLedger
# Decision HTTP Code Tool / Op Epoch Canary Detail
2. Last Dual P-256 Proof Envelope (humanProof + agentProof)

Human Delegation Proof (signed by HumanApprovalKey)

Enroll a delegation to inspect humanProof.

Agent Invocation Proof (signed by AgentSessionKey)

Invoke an operation to inspect byte-bound agentProof and SHA-256 digest.
3. Live HTTP / MCP Wire Transcript
0 wire events
Wire transcript populates as you enroll, invoke, or run red-team probes.

1. The Problem

Generic API proxies and raw bearer tokens inside agent runtimes give prompt-injected sessions ambient access to arbitrary endpoints, HTTP methods, and headers—and leak credentials through tool outputs or error traces.

2. The Goal

Reduce the agent interface to four fixed MCP tools (search_capabilities, describe_operation, connection_status, invoke_operation) where every call requires distinct human delegation and per-call agent P-256 proofs.

3. How It Works

A dedicated browser Worker self-checks its Content-Security-Policy via securitypolicyviolation before holding AgentSessionKey. The Cloudflare Durable Object verifies both P-256 signatures, active revocationEpoch, and SQLite consumed_nonces before injecting UPSTREAM_CANARY_TOKEN inside a fixed connector.

Architecture Dual P-256 proof custody, Worker CSP self-check & DO SQLite narrow MCP gateway
Browser Origin · Non-extractable P-256 keys & CSP-verified Dedicated Worker
Dual Key Custody

HumanApprovalKey + CSP-Locked Worker /workers/secret-custodian.js

CSP: default-src 'none'; script-src 'self'; connect-src 'self'
  • CSP self-check: fetches https://example.invalid/... and verifies securitypolicyviolation.originalPolicy before accepting AgentSessionKey
  • HumanApprovalKey: signs { agentJwkThumbprint, allowedOps, maxCalls, epoch, exp }
  • AgentSessionKey: signs SHA-256 digest of { opId, argsJson, nonce, epoch, ts }
Durable Object SQLite

CustodianLedger src/custodian-ledger.ts

  1. Reject arbitrary URLs/headers (403 ARBITRARY_TARGET_FORBIDDEN) and key collapse (403 KEY_COLLAPSE_FORBIDDEN)
  2. Verify WebCrypto ECDSA P-256 humanProof + recomputed SHA-256 agentProof (401 PROOF_DIGEST_MISMATCH)
  3. Enforce active revocationEpoch (401 EPOCH_REVOKED) and atomic SQLite consumed_nonces (409 NONCE_REPLAYED)
  4. Inject UPSTREAM_CANARY_TOKEN strictly inside fixed connector & scan response

Only 4 fixed MCP tools exposed: search_capabilities, describe_operation, connection_status, invoke_operation.

200 ALLOW

Fixed Connector Projection

UPSTREAM_CANARY_TOKEN stays inside DO SQLite
X-Custodian-Decision: ALLOW X-Custodian-Canary-Clean: true MCP-Protocol-Version: 2025-03-26
401 / 403 / 409 DENY

Fail-Closed Rejection

Zero secret material in error or audit receipt

Blocks URL/header injection, nonce replay, 1-byte tamper, stale epoch, key collapse, and unfit Worker CSP.

Cloudflare Edge Worker src/worker.ts

run_worker_first + DO SQLite

Enforces strict page CSP (frame-ancestors), serves /workers/secret-custodian.js with locked Worker CSP (connect-src 'self') and /workers/secret-custodian-permissive.js for Attack #6, and dispatches /mcp and /api/* to the CustodianLedger Durable Object.

Cryptographic delegation, byte-bound digest verification, atomic SQLite nonce consumption, and canary secret custody run across real browser WebCrypto, Dedicated Worker CSP enforcement, and Cloudflare Durable Object SQLite storage.
How This Is Set Up

Narrow 4-Tool Custody Boundary & Dual P-256 Proof Wiring

Replacing generic bearer-token proxies with fixed typed operations, dual ECDSA P-256 proofs verified in a Durable Object SQLite ledger, and a browser Worker that validates its own CSP before handling session keys.

Generic bearer proxy (over-privileged)
// Ambient API key + arbitrary request surface:
// Prompt injection can call any URL or leak Authorization header
await fetch(agentProvidedUrl, {
  method: agentProvidedMethod,
  headers: { Authorization: `Bearer ${process.env.PROVIDER_KEY}` },
  body: agentProvidedBody,
});
Custodian Narrow 4-Tool MCP + Dual P-256
// Fixed opId + human delegation proof + byte-bound agent digest:
await fetch("/mcp", {
  method: "POST",
  body: JSON.stringify({
    jsonrpc: "2.0", id: 1, method: "tools/call",
    params: {
      name: "invoke_operation",
      arguments: { delegationId, opId: "repo.release.list@v1",
        argsJson, humanPublicJwk, agentPublicJwk, humanProof, agentProof }
    }
  })
});
Worker CSP Self-Check Pattern (public/workers/secret-custodian.js)

Modeled directly on port-authority/sites/router/call-worker.js: the worker probes a cross-origin URL that its own connect-src 'self' policy must block and verifies event.originalPolicy before holding AgentSessionKey.

const EXPECTED_CSP = "default-src 'none'; script-src 'self'; connect-src 'self'";
self.addEventListener("securitypolicyviolation", (event) => {
  const observed = normalizePolicy(event.originalPolicy);
  if (observed === EXPECTED_CSP) {
    isFit = true;
    self.postMessage({ t: "fit", observedPolicy: observed });
  }
}, { once: true });
fetch("https://example.invalid/csp-self-check-expected-to-be-blocked-external");
What disappears

Caller-selected URLs, arbitrary HTTP methods/headers, raw provider tokens inside agent prompts/memory, and silent single-key collapse.

What becomes explicit

RFC 7638 distinct key thumbprints, SHA-256 byte-bound argsJson digests, atomic SQLite nonces, monotonic revocationEpoch, and Worker CSP self-verification.

Boundary limits

Revocation requires checking shared authoritative state (DO SQLite) on every invocation; offline bearer tokens cannot enforce instant epoch revocation or atomic single-use nonces.

Key terms & further reading
Model Context Protocol (Streamable HTTP)
A JSON-RPC 2.0 protocol over HTTP for exposing typed tools; narrowing it to 4 fixed tools avoids flooding an agent's context with wide REST schemas.
SubtleCrypto ECDSA P-256
The browser's built-in asymmetric cryptography API, creating separate non-extractable keys for the human delegator and the automated session.
RFC 7638 JWK Thumbprints
A deterministic SHA-256 hash of a public JWK used here to guarantee the human approval key and agent session key are distinct and cannot be collapsed.
securitypolicyviolation event
A browser event fired when Content Security Policy blocks a network request, letting the Dedicated Worker verify its own connect-src 'self' lock before holding keys.
Cloudflare Durable Objects (CustodianLedger)
A single-threaded SQLite edge store that enforces instant epoch revocation, single-use nonces, and server-only injection of the upstream canary secret.