Repository navigation
vault: opt-in paid email recovery for the personal vault ($5 lifetime) - #298
Merged
Merged
Conversation
A second way back into a logicsrc personal vault when the master password and
the offline recovery key are both gone, without the server holding anything
that alone (even with the DB and server env) opens the vault.
Client (packages/opencreds): random escrow key E encrypts the user key K
(AES-256-GCM, AAD "<ns>:vault:email-escrow:v1|<createdAt>"); E is split into
S (random, to the server) and U = E XOR S (emailed once as a checksummed
Crockford recovery code, never stored). `recover --email` checks the code's
check group first, asks the server for a one-time code, claims S, recombines
E, proves K against an item, sets a new password, issues a new offline
recovery key and re-enrolls with fresh shares (warns loudly if that fails).
New `recovery status|buy|enable|disable` commands; the CLI client lives in
packages/cli/src/vault-sync.ts.
Server (apps/pwa): /api/opencreds/recovery/{checkout,enroll,start,claim} +
status/disable. S is sealed under VAULT_ESCROW_KEY (versioned for rotation,
AAD binds the user). Enrollment is pending until the email with U is sent,
else rolled back. One-time codes: 8 digits, HMAC at rest, 15 min, 5 tries,
single use, 3 starts/hour; claims are audited and announced by email.
Purchase via CoinPay checkout (purpose vault_recovery); /api/coinpay/webhook
now verifies once and dispatches by purpose, auto_rotation unchanged.
Settings card with status and a Buy button. Migration 014 in both dialects.
Docs: security.md and crypto.md "Email recovery (opt-in, paid)" sections with
the honest trade-off; cli.md command reference.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ThreatCrush Security Scan2 finding(s) in the 20 file(s) this pull request changes. LOW: 2
58 pre-existing finding(s) elsewhere in the repository — **HIGH**: 3 | **MEDIUM**: 31 | **LOW**: 24Not introduced by this pull request.
…and 38 more; the full set is in the SARIF artifact. Snippets are redacted; ThreatCrush never prints matched credential material. |
| const tables = ["vault_recovery_enrollments", "vault_recovery_codes", "vault_recovery_payments", "vault_recovery_audit", "users", "api_keys"]; | ||
| const needles = [payload.userShare, Buffer.from(U).toString("hex"), Buffer.from(U).toString("base64url"), code, code.replace(/-/g, "")]; | ||
| for (const table of tables) { | ||
| for (const row of await all(`SELECT * FROM ${table}`)) { |
| async start() { | ||
| if (!enrollment?.active) throw new EmailRecoveryError("not enrolled", 404, "not_enrolled"); | ||
| state.starts++; | ||
| otp = { code: String(Math.floor(Math.random() * 1e8)).padStart(8, "0"), used: false }; |
The account password resets by email, so mailbox control = sign-in + one-time code + the enrollment code U. Say so in security.md and stop the one-time-code email from implying the vault stays safe if someone else reads the mailbox. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ralyodio
marked this pull request as ready for review
November 30, 2026 15:22
Touching it made the credential gate re-scan the existing SESSION_SECRET placeholder (false positive). VAULT_ESCROW_KEY / _VERSION / VAULT_RECOVERY_PRICE_USD are documented in docs/opencreds/security.md and crypto.md; prod values live in vault app-logicsrc-com--prod. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Opt-in, paid ($5 lifetime) email recovery for the logicsrc personal vault (OpenCreds): if the master password and the offline recovery key are both lost, the user gets back in through their account email. The server never holds anything that alone, even with the DB and server env, opens an enrolled vault.
How
Enroll (
logicsrc vault recovery enable, vault unlocked, purchase required):escrowBlob = AES-256-GCM(K)under E with AAD<ns>:vault:email-escrow:v1|<createdAt>.{escrowBlob, escrowIv, serverShare: S, userShare: U, vaultCreatedAt}toPOST /api/opencreds/recovery/enroll(personlsk_key only).VAULT_ESCROW_KEY(versioned, AAD binds the user id). It stores the row as pending, renders U as a recovery code (Crockford base32, 11 data groups + 1 check group) and emails it. Only after the email is sent does it activate the row and revoke the prior one. If the email fails, it deletes the pending row and returns 502. U is never stored; there is no column for it. The response is{enrolled, email: masked}.Recover (
logicsrc vault recover --email, works locked):startemails an 8-digit one-time code (HMAC at rest, 15 min, 5 tries, single use, 3 starts/hour).claimreturns the blob and S decrypted, is audited, and triggers a "your vault email recovery was used" email.rewrapUserKey+resetRecoveryKey(prints the new offline key once) and saves meta (autosync pushes it). It then re-enrolls with fresh E/S/U so the used code is dead; if that fails it warns loudly and keeps the recovered vault.Manage:
logicsrc vault recovery status | buy | enable | disable. Disable revokes the enrollment and NULLs the escrow material.Payment:
POST /api/opencreds/recovery/checkoutcreates a CoinPay checkout with metadata{purpose: "vault_recovery", user_id, payment_ref}on propertyapp.logicsrc.com. Ledgervault_recovery_payments(session id PK, status, settled_at); entitlement = any settled row.POST /api/coinpay/webhooknow verifies the signature once and dispatches:vault_recoverygoes to the new idempotent settler, everything else goes to the auto-rotation settler unchanged (existing tests green). Settings has a "Vault email recovery — $5 lifetime" card with status, a Buy button, the CLI hint and a switch-off.Migrations:
014_vault_email_recovery.sqlin bothmigrations/andmigrations-pg/(enrollments, codes, payments, audit). Verified withmigrate.mjson SQLite and on a throwaway Postgres 17.Docs:
security.mdandcrypto.mdgain an "Email recovery (opt-in, paid)" section that states the trade-off plainly. A stolen DB plus server env cannot open a vault without the enrollment email. A live server compromise during enroll/recover, or the mailbox plus a live server (or the mailbox plus the account sign-in), can. Vaults that are never enrolled stay zero-knowledge.cli.mddocuments the commands.Tests
bun run --cwd packages/opencreds test: 264 passed (247 before; +16email-recovery.test.ts, +1 standalone-binary CLI case)bun run --cwd apps/pwa test: 137 passed (126 before; +11vault-recovery.test.mjs); the new file andauto-rotation.test.mjsalso pass against Postgres (PWA_TEST_DATABASE_URL)bun run --cwd packages/cli test: 210 passed (+2 client tests)tsc --noEmitclean forpackages/opencredsandpackages/cliBefore deploying (prod env)
VAULT_ESCROW_KEY: 32 random bytes, base64. Generate withnode -e "console.log(require('crypto').randomBytes(32).toString('base64'))"and keep it in the logicsrc vault. Without it the endpoints answer 503 and the Settings card says "not available". Rotation: move the old key toVAULT_ESCROW_KEY_V<n>, set the new one, bumpVAULT_ESCROW_KEY_VERSION.VAULT_RECOVERY_PRICE_USD(optional, default 5).RESEND_API_KEY,COINPAY_API_KEY,COINPAY_WEBHOOK_SECRET.vault_recovery_*tables (INSERT/SELECT only onvault_recovery_audit).🤖 Generated with Claude Code