AI Security · Zero-Knowledge HITL 10 min read Updated 2026-11-18

Credential Delegation for AI Agents: Designing a Zero-Knowledge, Human-in-the-Loop Broker

When Claude Desktop, Cursor, or browser agents need to sign into dashboards without fine-grained OAuth scopes, pasting passwords or TOTP seeds into prompts creates catastrophic exposure. Here is how ephemeral ECDH envelopes, blind number matching, and atomic burn-after-reading state machines solve it.

AI Agent RAM Boundary ECDH P-256 (sk_A, pk_A) Private key stays in RAM Screen Match Code 47 Receives Ephemeral 6-Digit OTP Raw Base32 seed stays isolated Blind Broker State Relay PENDING → APPROVED FOR UPDATE → CONSUMED 🔒 Zero Plaintext Visibility Ciphertext wiped on consume Biometric Trusted Vault Blind 3-Option Match [ 19 ] [ 47 ✓ ] [ 83 ] Device OTP + ECDH Seal AES-256-CBC + HMAC-SHA256 Biometric Gate · Fail-Closed 1. AI Request (Ephemeral pk_A Only) ECDH P-256 · Match Code: 47 Private sk_A never leaves AI memory 2. Blind Broker (Zero Plaintext) 🔒 Strips match code, serves 3 candidates FOR UPDATE → CONSUMED → NULL 3. Blind Match + Biometric Seal [ 19 ] · [ 47 ✓ ] · [ 83 ] Device OTP + ECDH EtM Envelope
The relay broker coordinates state transitions over opaque ciphertext while private keys stay inside AI RAM and decrypted secrets stay on the user device until biometric approval

1. The AI Agent Authentication Trilemma

As personal AI workflows—MCP servers, browser-use agents, and local CLI assistants—move into production tasks, they hit an immediate authentication wall: most real-world SaaS consoles and internal tools lack scoped OAuth delegation and demand password + 6-digit TOTP entry.

Conventional workarounds fail cleanly across threat boundaries:

ApproachPlaintext ExposurePrompt Injection Blast Radius2FA / TOTP CompatibilityAudit & Instant Kill Switch
Paste Secrets into Prompts / EnvCritical: secrets enter LLM context windows, trace logs, and disk cachesCatastrophic: hidden web instructions can exfiltrate passwords and raw 2FA seedsFragile: sharing a Base32 seed grants permanent 2FA cloningNone: leakage forces manual credential rotation everywhere
Unattended Static Proxy TokensModerate-High: a compromised agent token unlocks continuous accessHigh: rogue tool calls silently harvest unrelated accountsWorks, but lacks interactive human judgment per domainPost-hoc logging only; no real-time human veto
HITL Ephemeral Envelope BrokerMinimal: AI holds scoped plaintext briefly in RAM; broker sees only opaque blobsContained: verified domain binding + blind 3-option number matching + biometricsDevice computes ephemeral 6-digit OTPs; raw seed never leaves vaultAtomic Burn-After-Reading + domain blocklists + global freeze

2. Ephemeral Zero-Knowledge Envelopes (ECDH P-256 + Encrypt-then-MAC)

Coordinating an AI agent running on a laptop with a biometric approval prompt on a phone or desktop client requires an online relay broker. If that broker can inspect granted passwords, it becomes a centralized high-value target.

Instead, each grant establishes a fresh one-time asymmetric channel using ephemeral ECDH P-256 (prime256v1) keys paired with AES-256-CBC + HMAC-SHA256 authenticated encryption:

  1. Agent Generates Ephemeral P-256 Keypair: Before every request, the agent generates (sk_A, pk_A) strictly in process RAM and submits only the uncompressed 65-byte public key pk_A;
  2. Device Unlocks Locally & Derives Session Key: Upon biometric approval, the user device decrypts only the selected record, spins up an ephemeral device keypair (sk_D, pk_D), computes shared = ECDH(sk_D, pk_A), and derives a 256-bit key K = SHA-256(shared || DomainTag);
  3. Least-Privilege Scoped Sealing: The device trims the payload to approved scopes only, creates a fresh 16-byte CSPRNG IV, encrypts with AES-256-CBC, authenticates (IV || Ciphertext) with HMAC-SHA256, and uploads { v, senderPubKey: pk_D, ciphertext: "iv:mac:cipher" };
  4. Constant-Time Verify & Unseal on Agent: The agent recomputes K from (sk_A, pk_D), verifies the HMAC tag prior to decryption, consumes the credential in RAM, and drops sk_A.
Ephemeral ECDH P-256 + Encrypt-then-MAC Pattern (Web Crypto API)
// 1. Derive domain-separated 256-bit session key over ECDH P-256
const sharedBits = await crypto.subtle.deriveBits(
  { name: 'ECDH', public: agentEphemeralPubKey },
  deviceEphemeralKeyPair.privateKey,
  256
);
const sessionKeyRaw = await crypto.subtle.digest(
  'SHA-256',
  concatBytes(new Uint8Array(sharedBits), utf8('lc_ai_grant_v1'))
);

// 2. Seal scoped payload with fresh 16B IV and Encrypt-then-MAC
const iv = crypto.getRandomValues(new Uint8Array(16));
const cipherBytes = new Uint8Array(
  await crypto.subtle.encrypt({ name: 'AES-CBC', iv }, aesKey, utf8(JSON.stringify(scopedPayload)))
);
const macBytes = new Uint8Array(
  await crypto.subtle.sign('HMAC', hmacKey, concatBytes(iv, cipherBytes))
);
const sealedEnvelope = `${toBase64(iv)}:${toBase64(macBytes)}:${toBase64(cipherBytes)}`;
1. PENDING (90s) Submit pk_A + Min Scopes Rate limit: 5/min (429) matchCode → AI Only 2. Blind Match & Bio Pick 1 of 3 (Fail-Closed) Isolate reason vs domain ECDH(sk_D, pk_A) → K 3. APPROVED (60s) Seal EtM Ciphertext iv : hmac : aes256cbc Ephemeral OTP, No Seed 4. CONSUMED FOR UPDATE Atomic wipe on read Replay → 409 1. PENDING (90s) · Rate Limited Agent sends pk_A · matchCode kept off device 2. Blind 3-Option Match + Biometric K = SHA256(ECDH(sk_D, pk_A) || tag) 3. APPROVED (60s) · Encrypt-then-MAC iv : hmac(iv||cipher) : aes256cbc 4. CONSUMED · SELECT ... FOR UPDATE Wipe blob atomically · Replay returns 409
Animated Flow: Agent ephemeral P-256 request -> Blind 3-option number matching & biometric sealing -> Atomic FOR UPDATE burn-after-reading
⚡ Live Browser Web Crypto Ephemeral Envelope Lab

Interactive Lab: ECDH P-256 Sealing, Blind Match & Burn-After-Reading

1. AI Agent (RAM) IDLE
Generate an ephemeral ECDH P-256 keypair inside browser RAM.
2. Trusted Device (Match)
Waiting for request: picking a decoy number fails closed.
3. Blind Relay & Consume
Relay holds state machine + opaque EtM envelope only.
Server Ciphertext View: -
Agent Decrypted Output: -

3. Defeating Prompt Injection, MFA Fatigue & Seed Leakage

Transport cryptography alone does not stop an attacker from manipulating human approval behavior. Real-world AI credential brokers must defend against malicious instructions embedded in untrusted web pages and push-notification fatigue:

  • Blind 3-Option Number Matching: For sensitive fields (such as passwords or notes) or first-time domains, the broker generates a 2-digit confirmation code revealed exclusively to the AI screen. The pending payload fetched by the user device strips the true answer and surfaces 3 shuffled options instead. Picking the wrong digit fails closed and immediately transitions the request to REJECTED;
  • Strict Provenance Isolation: Approval sheets physically separate broker-verified metadata (pre-bound agent identity, target domain, requested field badges) from the untrusted free-text reason supplied by the AI—preventing spoofed justifications from masking high-risk targets;
  • Device-Side Ephemeral OTP Delegation: When an agent only needs a 2FA code, the trusted device computes the live 6-digit OTP locally (plus the next-window token if fewer than 8 seconds remain). Raw Base32 TOTP secrets never enter AI memory or prompt context;
  • Sliding-Window Rate Limits & Domain Blocklists: Capping requests per user per minute (HTTP 429) suppresses MFA notification bombing, while one-tap domain blocking and a global kill switch let users isolate misbehaving agents instantly.

4. Atomic Burn-After-Reading State Machine

An approved ciphertext envelope must not linger in database tables or survive concurrent replay requests. Enforcing single-use semantics requires strict time-to-live bounds and transactional row locking:

  • Two-Stage Short TTLs: PENDING requests expire automatically after 90 seconds; APPROVED envelopes open a strict 60-second retrieval window before expiring and discarding ciphertext;
  • Eliminating TOCTOU Double-Read Races: A naive read-then-update permits concurrent callers to consume the same envelope twice. Execution must lock the row inside a transaction via SELECT ... FOR UPDATE, verify APPROVED state and expiry, flip status to CONSUMED, and overwrite encrypted_grant_bundle with NULL in the same atomic commit—returning 409 Conflict to any replay;
  • Bounded Task Leases: When workflows require multiple steps on one site, an optional 15-minute local task lease limits reuse strictly to that approved record and bounded call count rather than granting open-ended access.
PostgreSQL Row-Locking Burn-After-Reading Transaction
BEGIN;
-- 1. Acquire exclusive row lock to prevent concurrent double-consumption
SELECT id, status, consume_expires_at, encrypted_grant_bundle
FROM ai_auth_requests
WHERE id = $1 AND agent_id = $2
FOR UPDATE;

-- 2. Validate APPROVED status & 60s window (410 if expired, 409 if already consumed)
-- 3. Flip state and wipe ciphertext atomically in one transaction
UPDATE ai_auth_requests
SET status = 'CONSUMED',
    consumed_at = NOW(),
    encrypted_grant_bundle = NULL
WHERE id = $1;
COMMIT;

Key Architectural Principles

  • Combine ephemeral ECDH P-256 key exchange with Encrypt-then-MAC so relay infrastructure coordinates approvals without ever decrypting user secrets.
  • Pair blind 3-option number matching, untrusted reason isolation, and device-side ephemeral OTP computation to neutralize prompt injection and MFA bombing.
  • Enforce atomic row-level locking (FOR UPDATE) with immediate ciphertext erasure to guarantee strict single-use burn-after-reading delivery.

Connect Claude Desktop or Cursor With Zero-Knowledge Approvals

This entire ephemeral envelope protocol, blind number matching flow, and MCP integration run natively in LazyCoffee.