From c38ffdeff14d7abb0ec27f8f19ca4866a84281db Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Wed, 2 Dec 2026 22:37:50 -0800 Subject: [PATCH] fix(recovery): allow 10 recovery starts an hour, not 3 (#307) Three locked a real owner out for an hour after a few honest retries ("Too many recovery attempts. Try again in 1 minute(s)."). The guess budget stays negligible: 10 codes x 5 tries an hour against 10^8, and every start mails the owner. Confirmation links share the same allowance. Co-authored-by: Claude Fable 5.2 --- apps/pwa/src/lib/vault-recovery.mjs | 9 ++++++--- apps/pwa/test/vault-recovery.test.mjs | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/pwa/src/lib/vault-recovery.mjs b/apps/pwa/src/lib/vault-recovery.mjs index 7ee80cee..6437685c 100644 --- a/apps/pwa/src/lib/vault-recovery.mjs +++ b/apps/pwa/src/lib/vault-recovery.mjs @@ -13,7 +13,7 @@ // can: docs/opencreds/security.md says so plainly. // // Recovering releases S only against a fresh 8-digit code mailed at that time -// (15 minutes, 5 tries, single use, 3 per hour), and every claim is audited and +// (15 minutes, 5 tries, single use, 10 per hour), and every claim is audited and // announced by email. import crypto from "node:crypto"; import { readWebhook } from "@profullstack/coinpay-onboard"; @@ -25,7 +25,10 @@ import { coinpayClient, PROPERTY } from "./auto-rotation.mjs"; export const PURPOSE = "vault_recovery"; export const CODE_TTL_MS = 15 * 60 * 1000; export const CODE_MAX_ATTEMPTS = 5; -export const STARTS_PER_HOUR = 3; +// Ten, not three: three locked a real owner out for an hour after a few honest +// retries (2026-12-03). The guess budget is still tiny: 10 codes x 5 tries an +// hour against 10^8 possibilities, and every start mails the owner. +export const STARTS_PER_HOUR = 10; export const HOUR_MS = 60 * 60 * 1000; export const SHARE_BYTES = 32; export const IV_BYTES = 12; @@ -145,7 +148,7 @@ export async function createStepup(user, ctx = {}, now = Date.now()) { throw new RecoveryError(409, "no_stepup_method", "This account has no passkey and no connected CoinPay account to confirm with."); } const recent = await all(`SELECT id FROM vault_recovery_stepups WHERE user_id = ? AND created_at > ?`, [user.id, now - HOUR_MS]); - if (recent.length >= STARTS_PER_HOUR * 2) { + if (recent.length >= STARTS_PER_HOUR) { throw new RecoveryError(429, "rate_limited", "Too many recovery confirmations requested. Try again in an hour."); } const stepupId = crypto.randomBytes(24).toString("base64url"); diff --git a/apps/pwa/test/vault-recovery.test.mjs b/apps/pwa/test/vault-recovery.test.mjs index a6c53874..92cbdea1 100644 --- a/apps/pwa/test/vault-recovery.test.mjs +++ b/apps/pwa/test/vault-recovery.test.mjs @@ -308,9 +308,12 @@ test("codes expire after 15 minutes and die after 5 wrong tries", async () => { assert.equal(after.status, 410, "the right code is dead after five wrong ones"); }); -test("start is rate limited to 3 per hour per user", async () => { - // u_e has used 2 starts above; one more is allowed, the next is not. - assert.equal((await call(keys.u_e, "POST", "/api/opencreds/recovery/start")).status, 200); +test("start is rate limited per hour per user, with room for honest retries", async () => { + assert.equal(vr.STARTS_PER_HOUR, 10); + // u_e has used 2 starts above; the rest of the hour's allowance works, the next does not. + for (let i = 2; i < vr.STARTS_PER_HOUR; i++) { + assert.equal((await call(keys.u_e, "POST", "/api/opencreds/recovery/start")).status, 200, `start ${i + 1}`); + } const limited = await call(keys.u_e, "POST", "/api/opencreds/recovery/start"); assert.equal(limited.status, 429); assert.equal(limited.body.code, "rate_limited");