Unauthenticated MCP Challenge
Sends POST /mcp/docs without a Bearer header to trigger 401 + WWW-Authenticate: Bearer resource_metadata="...".
Track 9 · Agent Bridges & Discovery · Cloudflare Worker + SQLite Durable Object
Connecting an AI agent to remote Model Context Protocol (MCP) tools should not require copying static API keys into config files. This lab runs the full OAuth 2.1 + PKCE (RFC 7636) handshake live—covering RFC 9728 Protected Resource Metadata, RFC 8414 discovery, Dynamic Client Registration (DCR) vs. Client ID Metadata Documents (CIMD), RFC 8707 audience binding, and SQLite refresh-token family revocation.
The MCP authorization flow chains six specifications together. Missing one check—such as failing to bind tokens to /mcp/docs vs. /mcp/billing, trusting unsigned DCR client names, or skipping refresh-token replay revocation—quietly turns into cross-server token replay or spoofed consent prompts.
Standard browser OAuth 2.1 + PKCE delegation for remote MCP tools: users approve scoped access to a specific server with one click, zero copied API keys, zero server-side client-registration bloat, and automatic token-family kill-switches if a refresh token is stolen.
Click Run Full 6-Step Handshake below (or step through 1–6), switch between Unsigned DCR, Signed DCR, and Verified CIMD, then fire all 5 Red-Team Attacks and inspect the live HTTP wire trace and SQLite ledger.
Run every real OAuth 2.1 + WebCrypto S256 PKCE hop against the Cloudflare Worker and SQLite ledger.
—
Not registered
Not generated
None
Sends POST /mcp/docs without a Bearer header to trigger 401 + WWW-Authenticate: Bearer resource_metadata="...".
Fetches /.well-known/oauth-protected-resource/* then /.well-known/oauth-authorization-server to verify S256 and CIMD support.
Calls POST /oauth/register for stateless c_/cs_ IDs, or fetches and verifies /cimd/valid-client.json against its HTTPS URL.
Computes browser WebCrypto SHA-256 challenge, inspects GET /oauth/authorize (frame-ancestors 'none'), and submits approval for a single-use code.
Posts code, code_verifier, and resource to POST /oauth/token; DO burns code and mints a resource-bound token family.
Invokes MCP JSON-RPC tools/call on the bound resource with Authorization: Bearer ... and verifies 200 OK.
Trigger real OAuth replay, bad-PKCE, cross-resource, DNS-rebinding, and client-spoofing attacks against the Worker and SQLite ledger.
Run any of the 5 red-team attacks above to inspect live fail-closed responses and SQLite Durable Object state transitions.
Click any recorded request to inspect exact headers, status codes, CSP, and JSON payloads.
Wire trace details appear here as soon as you run a handshake step or attack.
Live snapshot from GET /api/ledger/state (hashes only; raw tokens are never stored).
| Family | Mode | Resource | Status / Reason |
|---|
| SHA-256 Prefix | Mode | Outcome |
|---|
| Event | HTTP | Detail |
|---|
/.well-known/oauth-protected-resource document returned via WWW-Authenticate so clients find the right OAuth server per path.S256./mcp/docs token is rejected on /mcp/billing.client_id directly to a verifiable HTTPS JSON document.WebCrypto S256 PKCE + fetch()
code_verifier and SHA-256 base64url challenge locallyc_), Signed DCR (cs_), and HTTPS CIMD URLs<iframe sandbox="allow-scripts"> sends real Origin: null POST to test DNS-rebinding defensesrc/router.ts/.well-known/oauth-protected-resource/* (RFC 9728) & /.well-known/oauth-authorization-server (RFC 8414)POST /oauth/register (stateless DCR) & /cimd/*.json URL-match verificationGET/POST /oauth/authorize with frame-ancestors 'none' consent CSPPOST /mcp/* validates Origin/Host (403) before Bearer + RFC 8707 audience check (401)Zero static registration table rows written for DCR; every token stored only as a SHA-256 digest.
OAuthLedger Durable Objectauth_codes · token_families · refresh_tokens · access_tokens
REFRESH_TOKEN_REUSE_FAMILY_REVOKED
Spent refresh replay kills the entire token family; bad PKCE burns the code; cross-resource tokens fail with 401; foreign Origin/Host fails with 403.
src/worker.ts backed by the OAuthLedger SQLite Durable Object. Plaintext authorization codes, access tokens, and refresh tokens are hashed with SHA-256 before persistence.
Adapted from ExtensibleWebApps/src/server/auth/mcp-oauth.ts and extended with MCP 2025-11-25 Client ID Metadata Documents (CIMD), SQLite Durable Object family revocation, and DNS-rebinding Origin/Host enforcement.
// Any caller can forge c_<b64url> offline without calling /oauth/register:
const forged = "c_" + b64url(JSON.stringify({
n: "Trusted Enterprise Agent",
r: ["https://attacker.example/callback"]
}));
// Zero DB rows stored, but client_name is unverified on /oauth/authorize!
// 1. CIMD enforces doc.client_id === fetched HTTPS URL:
if (doc.client_id !== clientId) throw new Error("CIMD_METADATA_MISMATCH");
// 2. Burn auth code in SQLite BEFORE verifying PKCE S256:
sql.exec("UPDATE auth_codes SET consumed_at = ? WHERE code_hash = ?", now, hash);
// 3. Spent refresh replay revokes entire token_families lineage:
if (row.spent_at !== null) {
sql.exec("UPDATE access_tokens SET revoked_at = ? WHERE family_id = ?", now, fam);
}