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:
| Approach | Plaintext Exposure | Prompt Injection Blast Radius | 2FA / TOTP Compatibility | Audit & Instant Kill Switch |
|---|---|---|---|---|
| Paste Secrets into Prompts / Env | Critical: secrets enter LLM context windows, trace logs, and disk caches | Catastrophic: hidden web instructions can exfiltrate passwords and raw 2FA seeds | Fragile: sharing a Base32 seed grants permanent 2FA cloning | None: leakage forces manual credential rotation everywhere |
| Unattended Static Proxy Tokens | Moderate-High: a compromised agent token unlocks continuous access | High: rogue tool calls silently harvest unrelated accounts | Works, but lacks interactive human judgment per domain | Post-hoc logging only; no real-time human veto |
| HITL Ephemeral Envelope Broker | Minimal: AI holds scoped plaintext briefly in RAM; broker sees only opaque blobs | Contained: verified domain binding + blind 3-option number matching + biometrics | Device computes ephemeral 6-digit OTPs; raw seed never leaves vault | Atomic 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:
- 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;
- 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);
- 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" };
- 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.
// 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)}`;Interactive Lab: ECDH P-256 Sealing, Blind Match & Burn-After-Reading
--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.
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.