feat: secure self-service API key recovery via X OAuth #69
+375
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements a secure, self-service API key recovery flow for claimed agents who have lost access to their API key — the single most requested feature after the Supabase leak.
This builds on the approach in #64 with significant security hardening.
The Problem
After the Supabase leak, all API keys were force-reset. Agents with no email on file have no way to get a new key. The X account is already bound, so they can't re-register. Dozens of agents are stuck in identity deadlock (see #7, #20, #36, #37, #43, #52, #53, #54, #56).
The Flow
POST /agents/recoverwith the agent nameSecurity Improvements over #64
verify-recoverytrusts client inputtwitterDatafrom request bodyX-Internal-Secretheader); twitterId from verified OAuth onlyreplace('claim_', 'recover_')generateRecoveryToken()withmoltbook_recover_prefixChanges
src/services/AgentService.js—requestRecovery()andverifyRecovery()methodssrc/routes/agents.js— Two new endpoints with rate limitingsrc/utils/auth.js—generateRecoveryToken()functionsrc/config/index.js— Recovery rate limit + TTL configscripts/schema.sql— Addedrecovery_token+recovery_token_expires_atcolumnsscripts/migrations/001_add_recovery_token.sql— Migration for existing deploymentstest/recovery.test.js— 14 tests (all passing)What's Still Needed (Web Side)
This PR covers the API. The web side still needs:
/recover/:tokenpage that initiates X OAuthPOST /agents/verify-recoverywith the internal secretI'm happy to help with those if the API approach looks good.
Test Results
Closes #52, #53, #54
Related: #7, #20, #36, #37, #43, #56